Two kinds of error
| Expected: your document or your input | Unexpected: the program | |
|---|---|---|
| What it is | Something you wrote or did that the program checks for and refuses | Something broke: a bug, a panic, a file the program could not read or write, a kernel that failed |
| Examples | An 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 reads | A 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 it | You, by editing the tile | A developer |
| How it is shown | A 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 panel | Prominently 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 code | 1 when the document is refused; 3 when the tile builds but fails the printability gate | 1 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:
- The program checks for it explicitly, and it has a name: a
dt::diagnostic code, or a gate verdict. - You can fix it yourself by changing the document or what you typed.
- Nothing is broken: the program did exactly what it should.
- 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:
| Boundary | What 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 routes | Answer 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 worker | Catches 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 handlers | Send 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.
| Code | Meaning |
|---|---|
| 0 | Built, and passed the printability gate |
| 1 | Refused or failed: a document error, a file that cannot be read or written |
| 2 | The command line itself is wrong (an unknown flag, a missing argument) |
| 3 | Built, but failed the printability gate |
| 101 | A 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
- Return
Resultand use?. Add context where it helps (which tile, which element, which file) rather than replacing the error. - Document errors are
miettediagnostics with adt::code, the span, and a help line. A new refusal gets a new code, not a reused vague one. - The compiler holds this rule.
clippy.tomlrefusesResult::ok,unwrap_or,unwrap_or_else,unwrap_or_default,map_or,map_or_else,is_ok_andandis_err_andon aResult, tests included. A site is one of three: the failure travels (?to its boundary); the conversion is infallible by construction (dt_value::idxfor a count that becomes a mesh id,LockExt::lock_unpoisonedfor a lock,var_osfor an optional environment variable); or it is one of the allowed silences below, marked#[expect(clippy::disallowed_methods, reason = "…")]on the smallest scope, the reason naming the kind.allow_attributes_without_reasonis on, so every#[allow]and#[expect]carries areason; a live lint is anexpect, so a stale one fails.crates/dt-lang/tests/silences_are_capped.rscounts the marked sites and fails when the count rises above its recorded number: a new silence is a reviewed change, and lowering the number is free. - No
let _ =,.ok(),unwrap_or_default()orunwrap_or(…)on a result that can fail for real. Writing into aStringcannot fail, solet _ = write!(s, …)there is fine. unwrapandexpectonly for what cannot happen; anexpectmessage says why it cannot. Anything a document or a file can cause is aResult.- A panic is a bug. It is never part of the plan, and a caught panic is still reported, saying it is a bug in dharmatiles, with its message and where it happened.
- No shipped program carries a crash switch. The exit-code tests make the program panic through
DT_TEST_PANIC, whichdt_eval::crash_switchreads only when itstest-panicfeature is on, and only the dharmatiles crate's dev-dependencies turn that on: a normal build reads no such variable. The preview's two routes that fail on purpose (/api/test-panic,/api/test-failure) exist only in the tests and in a build with the dharmatiles crate'stest-routesfeature, which nothing enables by default.
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:
| Field | What it holds |
|---|---|
kind | refused: 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, help | The words for the user, and what to do about it when the program knows. |
causes | The error chain, outermost first (source()); for a panic, where it happened. |
backtrace | Always 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. |
context | What 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:
- what was being done, what the panel said, and the kind;
- the environment: the dharmatiles version (the full build string), the build target system and printer, the tile and file, the browser, platform, screen and window size, the time (ISO) and the page address;
- the whole chain, the page's stack first and the server's backtrace after it.
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/dt-service/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.
| Field | What it holds |
|---|---|
seq, t | The order in the stream (it also resumes it) and the time, ISO, UTC. |
kind | A 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). |
severity | error, warning, note, info. |
scope | What reports it, and so what clears it: check, build, export, server. |
code, text, help | The 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, span | The 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}. |
data | Numbers and detail: a build's seconds and triangles, the gate's areas against their budgets, a failure's causes and backtrace. |
state | open, 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
- Document errors appear beside their line (the gutter mark and the underline, for a mistake the build finds as well as one the check finds) and in the messages panel, with the program's message and help. The page never re-checks a document itself; it asks the program (
/api/check-value, the build) and draws the answer. - An unexpected failure (a server error, an unreadable reply, a failed fetch other than the connection dropping) is a message, shown in the panel with what was being done ("Could not save 1x1-cliff-corner") and the error's words. A failure the page meets is told to the program, which puts it in the stream beside its own; if the program cannot be told, the page keeps the message itself. Logging it to the console as well is fine; logging it only there is not.
- A tile that is open and could not be read or built is never “No tile”. The tile level of the left panel says it could not be read and shows the first mistake (code, words, Go to line), from the same record as the view’s card and the messages (
firstErrorinweb/preview/js/messages.js); “No tile” is only for no tile open (tileLevelState, and a test that fails if another path says it). Every panel that shows a document that failed shows its mistakes, with no plan or no sheet to hang them on. - A lost connection is shown by the status line (reconnecting…), and the page tries again. That is expected, so it is not a message.
- Unhandled promise rejections and script errors are caught globally and shown the same way.
Every error has an address
- A diagnostic code (
dt::type) is made once, in the registry (dt-lang/src/codes.rs), and every error, note and message takes it from there by its constant. A code written as a string anywhere else fails a test, so a code the program prints is always one the docs know. - Every code has a page,
e/<code>.html, written bycargo xtask docsfrom the registry and from the section that explains it: what happened, what to do, a broken document and its fix, and the link on to the rule. The registry says that a code exists; adata-explainsmarker on the explaining section says where it is explained, and that is the only place that is written.docs --checkfails when a code has no explaining section, when a marker names no code, and when a page or anchor is missing or stale. The list of codes and the pages that explain the program’s own failures are Error codes. - Every error a terminal prints says where it is explained:
explain: <address>, thendharmatiles explain dt::…, which prints the page’s summary from the local copy of the docs. The address is the site’s, derived from the repository address inCargo.toml; it is never typed. - The editor’s messages with a code carry an Explain link, which opens the page served by the program from the docs it was installed with, so it matches the program and needs no network.
- A new code is one entry in the registry and one marker on the section that explains it.
Report this defect
- A message that means the program went wrong (a failure or bug of its own, a printability-gate failure, a diagnostic the registry calls a failure) says so on the wire,
reportable, made once (Message::reportable); a mistake in a document never is. The editor shows Report this defect beside Copy on exactly those rows. - The report is made by the program, once (
crates/dharmatiles/src/report.rs): the title is the code and the first line of the message, the labels aredefectand the code’s own, and the body is the text Copy gives (Message::text), then the environment, then the tile’s source unless Leave my tile’s source out is ticked. The editor asks for it (GET /api/messages/report?seq=N), shows it, and opens GitHub’s new-issue form filled in; it never files anything itself. - An address past about 8 KB carries a short body that says to paste the report. The whole report goes to the clipboard first, and if the clipboard refuses, the preview says so. The command line prints
report: <address>after a panic, and, when the address is shortened, writes the whole report to a file in the temporary folder and prints its path.
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:
- Per-viewer conveniences in the browser:
localStoragecan be unavailable (private windows); a remembered theme, layout or toggle then falls back to its default. - Best-effort cleanup: removing a temporary file or an empty cache folder after the real work has succeeded.
- Estimates: the cache of past build times that sizes the progress bar. Losing it changes only the estimate.
- Noting a use: the build cache's entry is touched when it is read, so the least recently used go first. A touch that fails (a read-only folder) only means the entry may go sooner. Nothing else about the build cache is silent: a damaged entry, an entry that cannot be written and a limit that is not a size are told (the cache of builds).
- You cancelled: closing a picker or a menu is not an error.
- Offline: a request made while the connection is down, which the page repeats on reconnect, with the chip showing the state.
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:
| Development | Staging and production | |
|---|---|---|
| Server to page | Error code, message, chain of causes | Error code and a plain message only; no internal details or traces |
| Server log | Everything | Everything, with the request it came from |
| Page | Details expandable and copyable | A plain message and what to do next |
| Target | Zero unexpected errors in production; every one that appears is investigated | |
Everything else on this page applies unchanged.
Tests
- Every
dt::refusal has a test that a document triggers it, with its code. - The preview's server has tests that a document error comes back as data and an internal failure as an error status in the one error shape: its kind, causes and a backtrace, and for a caught panic the panic's own stack.
- The page has tests that a failed reply becomes a nested
ServerError, and that the copied report holds both stacks and the environment. - A panic anywhere in a test run is a failure, never retried away. An intermittent crash is a bug to find (the Manifold level-set fix is the model: reproduce, find the cause, prove the fix).