Standard · the program, the preview, every element

Errors

Nothing is swallowed and nothing is hidden. When something goes wrong you see it, in words, with what to do next. A tile that fails loudly gets fixed; a tile that quietly comes out different gets printed, and costs a spool and an evening.

Target
zero panics, zero silent fallbacks
Your mistakes
shown where you made them
Our mistakes
shown loudly, never guessed past

Two kinds of error

Expected: your document or your inputUnexpected: the program
What it isSomething you wrote or did that the program checks for and refusesSomething broke: a bug, a panic, a file the program could not read or write, a kernel that failed
ExamplesAn unknown control (dt::unknown-control), a value out of range, a read nothing in the stack writes, a tile that fails the printability gate, an old spelling the language no longer readsA panic in an element, a Manifold failure, an I/O error writing an STL, a malformed reply from the preview's server, a build worker that died
Who fixes itYou, by editing the tileA developer
How it is shownA diagnostic with its code, the place in the file, and a help line saying what to write instead; in the preview, beside the line and in the error panelProminently and plainly: what failed, the error's own words, and the details (the chain of causes, the panic message and location) available to copy
Exit code1 when the document is refused; 3 when the tile builds but fails the printability gate1 for a failure that is not a bug (a file that cannot be read or written); 101 for a bug (a panic); never a 0

Telling them apart

An error is expected only when all four hold:

  1. The program checks for it explicitly, and it has a name: a dt:: diagnostic code, or a gate verdict.
  2. You can fix it yourself by changing the document or what you typed.
  3. Nothing is broken: the program did exactly what it should.
  4. The message says what to do: a help line, a suggestion, or the numbers that failed.

If any one fails, it is unexpected. When in doubt, treat it as unexpected: a loud report of something minor costs a minute, a silent one can cost a print.

One operation can fail both ways. Building a tile can be refused by its document (expected) or crash in a kernel (unexpected). Keep them apart by type, never by catching everything: document errors are diagnostics with codes, everything else is an error that carries its cause. Never show a kernel failure as if it were a mistake in the tile.

Where errors are handled

Below the boundaries an error travels up, unchanged except for added context. It is handled only at a boundary, where someone can be told:

BoundaryWhat it does
The command line (main)Prints diagnostics with miette (code, span, help) and other errors with their chain of causes, to stderr; exits 1
The preview's HTTP routesAnswer a document error as data the page shows inline; answer anything else with an error status and the one error shape; log it to the server's stderr
The preview's build workerCatches a panic per build, reports it to the page as a failed build in the same error shape (a bug, with the panic's stack), logs it, and keeps serving; the next edit builds again
Library sweeps (build --all)Report every failing tile by name with its reason and carry on to the next; the run exits 1 if any failed
The page's event handlersSend an unexpected failure to the one error panel (showError in web/preview/js/problems.js) or the connection chip; never only in the console

Exit codes

The command line follows Rust's own convention, the one the Rust compiler uses: 1 when your input is wrong, 101 when the program has a bug.

CodeMeaning
0Built, and passed the printability gate
1Refused or failed: a document error, a file that cannot be read or written
2The command line itself is wrong (an unknown flag, a missing argument)
3Built, but failed the printability gate
101A bug: a panic, anywhere, including one caught while building the library

When a run has more than one outcome (build --all), the worst wins: 101, then 1, then 3, then 0.

In the Rust code

The error from the server to the screen

One error path runs from a Rust failure to the pixel, and everything on it is the same shape, so a bug report always carries the whole story.

On the server (crates/dharmatiles/src/preview/fail.rs) every reply that is not a success is {"error": {...}} with the right HTTP status:

FieldWhat it holds
kindrefused: the request was wrong (no such tile, a name that cannot be a file); the page shows it where it asked. failure: the program tried and could not (a file it could not write); the message is the headline. bug: a panic.
message, helpThe words for the user, and what to do about it when the program knows.
causesThe error chain, outermost first (source()); for a panic, where it happened.
backtraceAlways captured, on every kind. A panic's is taken in the panic hook, where the stack still is, and picked up where the panic is caught; other errors take it where they are made. The frames of the capture itself are left out.
contextWhat the server was doing (route, tile), the program's full version string, and when (at_ms).

A panic caught round a route, a build or a draft is a bug with the panic's message, its place and its stack. A build that panics or cannot be encoded also puts the same structure in the tile's failure in the event stream, and a draft puts it in its reply. A mistake in the tile's text and a gate verdict are not failures and keep their own shapes.

In the page, host.js turns a reply that is not a success into a ServerError (web/preview/js/server-error.js) holding those fields. The error for what the page was doing has it as its cause, so one error carries both stacks. A reply without the structure (a plain-text refusal) becomes one with its words and no backtrace. Everything then goes through showError(what, err): script errors, unhandled rejections, a store subscriber that throws, a failed reply, a build that failed.

On the screen, one row in the messages panel (the failure is a server message) says it plainly. A failure or a refused shows its own message (and help) as the headline. A bug, and anything the page threw itself (a TypeError, a reply it could not read), shows Something went wrong inside dharmatiles with what was being done, and the words under it. Only a bug takes the interface's danger red (--err); a failure or a refusal is a plain note. The entry opens into the chain, each level indented and in monospace: the page's error and its JavaScript stack, then the server's error with its causes and backtrace, long traces scrolling. Every entry copies: a tile's own errors (a dt:: diagnostic, or dt::build, a bug met building the tile) have a copy icon giving the code, place, words and help, the source lines round it and the environment. Copy details on a failure copies a plain-text report:

The button reads Copied when the text is on the clipboard. When the browser refuses the clipboard, it says so beside the button, and the details stay open to select by hand.

One stream of what happened

Errors are one kind of thing the preview learns about a tile, and the rest (a check read it, a build took 2.1 s, the gate's numbers, a note, an export) is the same sort of thing, so they travel as one message (crates/dharmatiles/src/message.rs) on the event stream, and every surface is a view of it. A surface never holds a message of its own: fix the cause and the row, the mark in the source and the count go with it.

FieldWhat it holds
seq, tThe order in the stream (it also resumes it) and the time, ISO, UTC.
kindA closed list: progress (a build is under way; never kept once it ends), check, build, gate, error (a mistake in the tile), note (dt::steep, dt::edge), export, server (a failure of the program's own, or the page's).
severityerror, warning, note, info.
scopeWhat reports it, and so what clears it: check, build, export, server.
code, text, helpThe diagnostic's code (dt::look), the words and what to do. The text is the program's, never reworded by a surface.
tile, tile_name, node, spanThe tile (its id), the stack entry it is about (the entry's key, the id the page and the view share), and the place in a file: {file, line, col, offset, len}.
dataNumbers and detail: a build's seconds and triangles, the gate's areas against their budgets, a failure's causes and backtrace.
stateopen, until a later check or build of the same scope for the same tile no longer reports it; then cleared. A message said again keeps its place and its time.

The text form (Message::text) is one function, used by the panel's copy, GET /api/messages?format=text and so an assistant: a header (10:41:40.771 error dt::look tree-err tile/tree/0 tree-err.dtile:8:9), then the words, help: and the numbers, indented. GET /api/messages?tile=&since=&state=&kind=&severity=&format=text|json reads the log (tile is an id, a path or a name); the same messages arrive as message events on GET /api/events, every kept one first after the snapshot, then each as it is said.

What emits them: check (the editor's check of the text and the plan pass of a build: its mistakes, and the notes that used to reach no one), a build (its timing, and the gate's verdict and numbers as two messages; its mistakes), an export, and the server's one error path: every 5xx the server answers, a build that panicked, and a failure the page reports (POST /api/messages, from showError) become server messages with the chain and the backtrace in data. A refusal with its reason (a 4xx) is for the caller to show where it asked, so it is not a message. Progress is not kept: its ticks are the progress events, and the one progress message that says a build is under way is dropped when the build ends.

In the preview

Every error has an address

Report this defect

The few allowed silences

An error may go unshown only when it changes nothing you make or see, and the code says why in a comment where it is ignored:

Output never changes silently

No fallback may quietly change what is built. If a value cannot be read, the tile is refused; it is never built with a default instead. If a repair changes the mesh (voids filled, pinches moved), the build says so and the build record counts it. If an element leaves out a piece it could not make (a hull or a band that came out degenerate), it counts what it left out in the build record, by element. The printability gate is never loosened and geometry is never culled to pass it. What prints is what the document says, or the program says why not.

If part of it is ever hosted

dharmatiles runs on your own machine, so the full details of an error are always yours to see. Tiles are always generated on your own machine: by the installed program, or in the browser through WebAssembly, which counts as local here. A server never generates tiles. If a hosted part is ever added (a shared library, accounts, sharing tiles), it follows a development, staging and production split:

DevelopmentStaging and production
Server to pageError code, message, chain of causesError code and a plain message only; no internal details or traces
Server logEverythingEverything, with the request it came from
PageDetails expandable and copyableA plain message and what to do next
TargetZero unexpected errors in production; every one that appears is investigated

Everything else on this page applies unchanged.

Tests