Remote / foldkit-remote-server
Diagnostics
A server answers some failures without telling the caller why. Each is a
typed diagnostic, reported through Diagnostics.Reporter (foldkit-surface's
channel, re-exported by foldkit-remote), which by default is Effect's log:
_tag | level | When |
|---|---|---|
ServerDefect | error | Something on this side broke (a layer, a resolver, a handler's defect) and the caller was answered Internal error; it carries the cause. |
AnswerUnread | warning | A mutation committed, but reading its answer failed: the client reads those rows again. |
PublishFailed | error | A mutation committed, but its live publish failed: live subscribers do not hear it. |
ClockSkewed | warning | A write's time was past clockSkew from the server's clock (a client clock that is off, or a durable write that waited), so the server wrote its own; it carries sent, own and bound. |
Provide another reporter as any service: Layer.succeed(Diagnostics.Reporter,
report) in the layer the handlers run in. serveFetch takes one with the
request beside it, used for everything that request runs, a broken layer
included:
ts
serveFetch({
server,
resolvePrincipal,
layer: (env: Env) => databaseLayer(env),
diagnostics: (diagnostic, request) =>
Effect.logError(`${request.method} ${request.url}: ${diagnostic.message}`),
})In a test, Diagnostics.collect() gives a reporter and the array it fills.