Errors

Every bridge failure carries code and message, plus requires on a not-implemented. Branch on the code: most failures are rejected invokes, but window, tray, updater and others answer a typed { ok: false, code, message } value inside the { ok: true, result } envelope. The bridge gives that value a non-200 HTTP status mapped from the same table below, so the status agrees with the code instead of being informational.

Codes

codeHTTPcause
unauthorized401missing or wrong bearer token
bad-origin403present and foreign Origin header
not-found404unknown asset route, or fs.readTextFile on a missing file
unknown-plugin404PluginRegistry.invoke only — the bridge flattens names into unknown-command
unknown-command404no handler under <plugin>.<command>, including an unknown plugin over the bridge
bad-json400the invoke body is not JSON
bad-request400malformed payload, bad argument, or a definePlugin violation
handler-error500a handler threw something that was not a CrustError
too-large413body over 2 MiB
not-implemented501a command returned notImplemented(...)
forbidden403a window label does not hold a capability covering the command
outside-scope403an fs path resolves outside every configured fs.scope prefix, or touches the scope store

Messages

codemessagewhen
unauthorizedmissing or bad bearer tokenthe header is absent or wrong
unauthorizedmissing or bad document tokenthe document route's ?token= is absent or was never issued
bad-jsonbody is not jsonJSON.parse failed on the body
too-largepayload too largethe declared or actual body exceeded 2 MiB
bad-requestbody needs { plugin, command, args }the JSON body has no string plugin and command
bad-requestbinary invoke needs ?plugin= and ?command=a non-JSON body with the command missing from the query string
unknown-commandthe bare key, e.g. fs.nopeno handler is registered at that key
unknown-pluginno plugin named "fs"registry lookup only, never over the bridge
not-implementedthe first argument of notImplemented(...), with requires set to the seconda command declined instead of pretending
handler-error<plugin>.<command> plugin handler threw: <message> (the error came from the handler, not the bridge)a handler threw; its code, status and requires are kept
forbiddenthe action, the window label, and the capability that would have allowed itthe label holds no capability covering the command
outside-scopefs: <path> is outside the app's scopethe path resolves outside every prefix; the store and a page's own grant widening name the fix instead

not-implemented reaches the page as { "code": "not-implemented", "message": "…", "requires": "NSPasteboard" }, so a caller can tell "this platform cannot do it" from "the call was wrong". A typed value's own code travels the same way: needs-activation from accessibility.elementCount is the read telling the caller the app was never activated, not a platform gap.

A definePlugin violation is bad-request at declaration time, not at invoke time: definePlugin: name must be a non-empty string, definePlugin: name "a.b" may not contain a dot, definePlugin: plugin "x" needs a commands object, definePlugin: plugin "x" has no commands, definePlugin: x.a.b may not contain a dot, definePlugin: x.y is not a function.

One sheet at a time

The shim holds one panel, one done flag and one path list, so a second openPanel or savePanel while a sheet is up answers SHIM_PANEL_BUSY (status 5) before touching anything. The adapter turns that into a thrown message, which the bridge reports as handler-error — HTTP 500 — naming the panel that is already up and the way out:

crust: savePanel refused (busy); an NSOpenPanel sheet is already up, and only one panel can be open at a time — answer it, or call dialog.cancel, before asking NSSavePanel for another

openPanel uses NSOpenPanel and savePanel uses NSSavePanel; the busy refusal names whichever class is already up. A cancelled pick is never an error: the panel answers { paths: [] }, and dialog.cancel answers { cancelled: true, paths: [] }, or { cancelled: false, paths: [] } when nothing was pending — an ordinary race with the user.

window and tray

These two return a typed failure value rather than a rejected invoke: { ok: false, code, message }, with label on every window failure that knows one. The bridge maps the code to a non-200 status through the CrustError table — invalid-* → 400, unknown-window and destroyed → 404, unknown-adapter → 501, handler-error → 500, server-side faults (signature-mismatch, hash-mismatch, unverified-artifact, relaunch-failed, io-error, corrupt, sql-error, contract-violation) → 500, any other unmapped code → 400 — while the { ok: true, result: … } envelope and body stay unchanged. Because the body is unchanged, await window.close() still resolves with the typed failure instead of rejecting, so a caller that ignores the result keeps working.

coderaised when
invalid-labelthe command needs { label } with a non-empty string
invalid-titlecreate or setTitle got a title that is not a string
unknown-windowno open window carries that label
duplicate-labelcreate names a label that is already open
invalid-sizecreate width or height is not a positive integer — refused, never clamped
invalid-urlcreate url is present but empty or not a string
unknown-adapterthe adapter has no create, checked before the arguments
handler-errorthe adapter threw, or answered without tracking the new label
codemessage
invalid-labelcrust: window command needs { label } with a non-empty string, got …
invalid-titlecrust: window.setTitle title must be a string, got 42
unknown-windowcrust: no window labelled "main"
duplicate-labelcrust: a window labelled "main" already exists; a second one would replace it in the platform's map. Close it or pick another label.
invalid-sizecrust: window.create width must be a positive integer, got 1.5 in …
invalid-urlcrust: window.create url must be a non-empty string when given, got "" in …

Tray codes are invalid-text, invalid-menu, unknown-adapter, destroyed and handler-error. destroyed means the status item was already torn down; a second createStatusBar() throws until the first is destroyed.