Skip to main content
Everything that crosses a boundary ends in a Result: a client call, a task, a ctx.try, or a test kernel client call.
A refusal is one flat value. It has no nested object for a finer cause.
  • code is what your code branches on. It is a host code or one of the function’s own codes.
  • reason is set on a host code when the host names a precise cause you can act on, such as "BudgetExhausted" on Limit or "NotCleared" on Disallowed. Its type follows code: when you narrow code to "Limit", reason narrows to the reasons Limit has. Reasons lists every one.
  • retryAfter sits beside a reason that carries it, when the host knows how many milliseconds remain until the bound refills.
  • kind: "app" marks the function’s own code. Such a refusal never carries a reason. It carries data when its refuses declares a payload for that code.
  • message is the sentence the caller is entitled to read, and you can show it. It never starts with the code or the reason, so never parse it.
  • The host’s Forbidden refusal carries guard, the path of the guard’s declaration.
A committed client mutation’s result also carries its commit version.

Refuse with an app code

A function declares the app codes it may refuse with in refuses. ctx.refuse(code, message) leaves the transaction with one of them:
bijection/notes.ts
An app code is PascalCase and never equal to a host code. A code missing from refuses does not type-check, and the error names the fix. The caller’s Result carries "EmptyNote" | HostCode. To hand the caller typed facts with a code, declare its payload: write refuses as an object from code to payload type, with null for a code that carries none. Pass the payload as ctx.refuse’s third argument:
The caller’s refusal carries { kind: "app", code: "NotEnough", data: { available } }, with data typed by the declaration. The payload is checked against its declaration as the refusal leaves the function: a payload that does not match, or one passed for a code that declares none, ends the call Failed. The payload reaches the caller however it called: a call’s or a trial’s result, an HTTP refusal, a live watch’s error event, an HTTP route’s refusal and an MCP tool’s refusal (in _meta["com.bijection/error"]) all carry it. The refused invocation discards its staged writes. An ordinary thrown exception ends the call Failed. Unknown, Withdrawn, Erased, Expired, Disallowed and Forbidden are host-only codes. If an app raises any of them, the call ends Failed with the original message. The host supplies reason, guard and retryAfter. An app can declare a code such as RateLimited and carry a retry delay in its typed data.

Refusals in helpers

A helper returns a refusal as a value. It never throws one:
The function that calls the helper raises its refusal with ctx.refuse(refusal). This uses the same rules as raising a code directly.
A thrown refusal is a bug: the function ends Failed, with the message “A refusal was thrown: return it, or pass it to ctx.refuse”. isRefusal(value) tells a refusal apart from any other value.

Call a function and go on

A query can use ctx.call and ctx.try to enter another query. A mutation can enter either kind. The at option selects a valid instant for a query. ctx.call(fn, args) answers the callee’s value:
  • If the callee refuses, the caller is refused with the same code, reason and message.
  • If the callee throws, the caller is refused Failed.
Use ctx.call to pass on a callee’s host refusal. Re-raising a refusal returned by ctx.try with ctx.refuse(refusal) applies the app’s refusal rules. To go on when the callee refuses, use ctx.try(fn, args). It answers how the callee ended as a Result: A callee that refused or threw discards its staged writes, submits and acts, and the caller’s transaction goes on. Any disclosure audit the callee committed while opening through a release survives. Both take { in, at } to call into another world or at another valid instant. A refusal ends the invocation it happens in, even when code catches it. ctx.try is the only way past a callee’s refusal. No refusal crosses ctx.try. The caller receives the callee’s outcome as a Result. A store conflict, an authentication failure and a host failure affect the whole transaction. The host handles store conflicts by retrying the whole transaction. A write guard is judged at commit, against the facts the transaction leaves (one transaction, several acts). Its Forbidden refuses the outermost invocation that commits. An act.enter guard is judged when the call enters, so ctx.try answers it as a Result. An act.disclose guard on ctx.open(sealed, { release }) is judged before the value is unsealed, and again at commit. For a protected query, entry decisions made in the caller’s scope stay clear, and their observations stay in the caller’s read set. The query body reads a private snapshot. Its observations stay with the sealed result, outside the caller’s retry and watch dependencies. The caller can pass along the handle. A frame clearing the query’s label can open it and read the Result. bijection check reports CallAbove for a known protected ctx.call and for either form of synchronous call to a known protected mutation. Use ctx.submit with the mutation’s label as under for deferred work. Submit work at a higher label

Host codes

The host answers with twelve codes, and they are the same at every boundary: Disallowed and Forbidden are the two kinds of no:
  • Disallowed means nothing said yes. Add a role to allow, or grant one that clears the label.
  • Forbidden means a yes was overruled by a guard.
A guard’s sentence is the message its Forbidden refusal carries: forbid(scope, { message, where }).

Reasons

Branch on reason when the host code alone is too coarse:
Reason<"Limit"> names the reasons of one host code, and Reason names them all. The list is generated from the host’s own refusal registry. Only the reasons below cross a boundary. The host keeps every other cause for its own logs and sends the host code alone, so a refusal with no reason is common. sys.logs facts record each run’s code and reason the same way. A reason never reveals what the caller may not see. When the code an uncleared caller gets stands in for something hidden from it, the refusal carries no reason. That covers an erasure, a hold, a hidden fact and a label or place the caller does not clear. Erased reaches only a frame that clears the erased unit’s label. Any other frame reads Absent, exactly as if the unit never existed. A common case is a function open only to role.anyone or role.signedIn with a non-public under. The class grant the program issues at install clears only public, so entry fails for lack of clearance with Disallowed and reason NotCleared. A refusal is labelled by everything it read, so its message never reveals data above the caller’s clearance. A production deploy that changes calling contracts without acknowledgment answers Conflict. Review the changes with bijection deploy --trial, then pass the reviewed paths to --accept-breaking-contracts.

Every public reason

retryAfter rides only beside BudgetExhausted (RetryAfterReason). The authoring diagnostic ClearsPublic identifies a role that explicitly lists label.public in clear. Omit it because every role clears public. The authoring diagnostic OpenRouteRoles identifies a route that declares roles with verifier.none(). Require a verifier or remove those roles.

Adding and changing reasons

A client reads a reason it does not know as absent. The host adding a public reason therefore breaks no client: an older client sees the host code alone. Renaming or removing a public reason, or moving it to another host code, is a breaking change.

Handle a result on the client

A client call never throws a refusal, so branch on result.ok. useWatch and useMutation answer the same Result. For Unknown, call again with the original arguments and pass the refusal’s once in the call options. client.trial(fn, args) runs a call in a discarded world and answers { result, writes, tasks, validUntil }, with the refusing guard in result.guard.

In tests

A client from k.as(principal) answers a Result. A refused fixture setup throws Refused, whose result carries the refusal. See the test library.

Read and write limits

A function that reads or writes more than its budget refuses Limit. Bound every read: ctx.list takes only a selection that ends in .first(n), and an index must serve each selection. See Indexes and Limits.

Server errors

A deployment redacts thrown errors before they reach a client. The client sees Failed, the function’s path and the request ID, not the original message or stack. The deployment logs the full error: find it on the Logs page or with bijection list sys.logs. See Debugging.