Result: a client call, a
task, a ctx.try, or a test kernel client call.
codeis what your code branches on. It is a host code or one of the function’s own codes.reasonis set on a host code when the host names a precise cause you can act on, such as"BudgetExhausted"onLimitor"NotCleared"onDisallowed. Its type followscode: when you narrowcodeto"Limit",reasonnarrows to the reasonsLimithas. Reasons lists every one.retryAftersits 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 areason. It carriesdatawhen itsrefusesdeclares a payload for that code.messageis 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
Forbiddenrefusal carriesguard, the path of the guard’s declaration.
version.
Refuse with an app code
A function declares the app codes it may refuse with inrefuses.
ctx.refuse(code, message) leaves the transaction with one of them:
bijection/notes.ts
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:
{ 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:ctx.refuse(refusal). This uses the same rules as raising a code directly.
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 usectx.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.
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:
Disallowedmeans nothing said yes. Add a role toallow, or grant one that clears the label.Forbiddenmeans a yes was overruled by a guard.
message its Forbidden refusal carries:
forbid(scope, { message, where }).
Reasons
Branch onreason 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
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 fromk.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 refusesLimit. 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 seesFailed, 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.