This site uses one functional cookie to keep feature rollouts consistent for you. Nothing is set until you choose. See the privacy notice.
Dev notes
I created a calendar on the live site and it said it couldn’t save. A toast slid up holding a wall of JSON about calendar.role. The calendar had been created. Two separate bugs were hiding behind that one screen, and the one I want to write about is the second: the page was willing to show a person a developer’s diagnostic as if it were a message to them. Nobody had ever looked at it, including the AI that helped write the code around it.
This is what the toast said, character for character:
[
{
"code": "invalid_value",
"values": [ "owner", "editor", "viewer" ],
"path": [ "calendar", "role" ],
"message": "Invalid option: expected one of \"owner\"|\"editor\"|\"viewer\""
}
]Under it, the modal said “Couldn’t save the calendar. Please try again.” Trying again was the wrong advice. The insert had already committed, so a retry would have made a second calendar. A write that succeeded, reported as a failure, with an invitation to do it twice.
The web app checks every response body against a schema, and the calendar schema requires a role. The list query gets one from a membership join. A create doesn’t join anything: it returns the row it just wrote, and the calendars table has no role column. The mapper that builds the response had been written to tolerate that:
role: row.role ?? undefined,
Tolerant on the API side, strict on the web side, and neither noticed the other. The schema threw after the write. Editing a calendar did the same thing for the same reason. Only the owner can make either call, so the role was always knowable. The API now says owner, and the web app treats a missing role on those two responses as the caller’s own, so whichever deploys first doesn’t matter.
That is the part I would have missed if I had only fixed the role. The global handler for a failed write looked like this:
const message =
error instanceof Error && error.message
? error.message
: "Something went wrong. Please try again.";
toast.error(message);A ZodError is an Error, and its message is the JSON of every issue it found. So the check I had written, “is there a message?”, passed, and the JSON went to the screen. The docstring above it says the goal out loud: no API failure is silent. It was true. Nothing was silent. Some of it was unreadable.
The test for it had the same blind spot. It threw new Error("You already have an active season wallet") and asserted that sentence appeared, which proves messages somebody wrote reach the screen. It said nothing about messages nobody wrote for a person.
There are really three kinds of thing that get thrown, and a person should only ever read the first:
new Error("You already have an active season wallet"). It shows as written.ZodError (the response didn’t match what the code expects), a SyntaxError (an error page came back where JSON was expected), a TypeError (fetch rejected). These go to the console with the original error attached, and the person reads the screen’s own fallback. A rejected fetch gets its own line, because “couldn’t reach the server” is something they can act on.undefined. Fallback.That became one function, userFacingErrorMessage(error, fallback). The toast uses it, the query hooks use it, and so do the dozen places that had been rendering error.message themselves: the fantasy pages, the gallery wall, the calendar invite, the restock flow. After the sweep a search for error.message in the client finds only messages written on purpose. The toast write-up has the original reasoning for catching every failed write in one place; this is the other half of it, deciding what that place is allowed to say.
A write that succeeds and then throws while reading its own response is a pattern, so I went looking. I read every write across both repos whose response is validated or has fields read off it, about two dozen, and compared what the schema requires with what the API really sends: flags, operator, restock, budget, ZeroProof, check-in, gallery walls, calendar events, cards and countdowns. Two were wrong, and they were the two calendar ones. Everything else matched.
It also turned up things that weren’t that bug but sit next to it. The operator proxy catches any error from a write, including a failed validation, and falls back to demo data, which can turn a write that landed into a “not found”. The API’s own validation errors read like calendar.role: Invalid option. And one calendar card update builds its query with a placeholder style the database library doesn’t read. None of those are fixed in this change. They are written down where I will find them.
This is the part I most want to keep. The error handling here was written with an AI assistant, and it did the thing I asked: every failure surfaced. The tests proved a message was shown. The audit I ran across the codebase afterwards found thirteen bugs that were each a failure dressed up as a plausible result, and this one was not on the list, because it is the opposite. A failure dressed up as internals. Nobody, human or otherwise, had looked at the screen.
I don’t think that is an accident. An assistant optimises for the goal in the prompt and for tests that go green. “No failure is silent” is checkable in code. “A person can understand and act on what they see” is not, unless you make it so. The code reads fine, the types are fine, the test is fine, and the page is bad. Things I check now:
error.message reaches the screen, someone has to have written that sentence for a reader. If the answer is a library, it is a leak.