11.4. Report diagnostics and handle failures explicitly
Feature guides / 11. Operating a federation application · Example context
eduGAIN's operator wants to learn that a recommended status endpoint is missing, while Research Portal needs a definite rejection when a chain is invalid. A diagnostic message and an operation's result answer different questions.
How to use it
Connect the host's options.logger, or a protocol role's logger override, before exercising its operation. Core defines the shared Logger interface. The library does not install an output adapter; your application chooses the sink. Both synchronous and asynchronous sinks are supported, and sink failures leave protocol processing unchanged. Normative language.
import { Leaf } from "@oidfed/leaf";
import { entityId, type CryptoContext, type Logger, type TrustAnchorSet } from "@oidfed/core";
type Level = "debug" | "info" | "warn" | "error";
export function applicationLogger(send: (level: Level, message: string) => Promise<void>): Logger {
return {
debug: message => send("debug", message), info: message => send("info", message),
warn: message => send("warn", message), error: message => send("error", message),
};
}
export async function ligoWikiWithLogging(
crypto: CryptoContext, trustAnchors: TrustAnchorSet, logger: Logger,
) {
const ligoWiki = await Leaf.create({
entityId: "https://wiki.ligo.example", authorityHints: ["https://incommon.example"],
crypto, trustAnchors, metadata: { federation_entity: {} }, options: { logger },
});
return {
ligoWiki,
async discoverUmeaOp() {
const result = await ligoWiki.discoverEntity(entityId("https://op.umu.example"));
if (!result.ok) return result; // Stop the dependent operation; logs do not accept evidence.
return result; // Continue through the appropriate protocol role.
},
};
}
What your application owns
Choose your sink, retention, and correlation outside the library. Messages are plain text; they do not reliably identify a particular entity in a multi-entity traversal. Debug describes work, info records ordinary events or advisory recommendations, warn calls attention to a recoverable or validation problem, and error describes an operation failure where emitted. A SHOULD is not automatically a warning and a MAY is not a requirement. Rejections still occur without a logger. Result APIs use ok/value/error, chain validation uses valid, and schema parsing uses success/data/error; constructors and some authority methods can throw. Avoid showing untrusted error detail verbatim in an HTML page.
Make diagnostics useful without changing decisions
Supply a logger through the same options used for the operation. Messages should help the developer recognize the specification concept or failed stage. The library keeps rejection behavior independent from whether logging is configured or whether the sink succeeds.
Add request correlation in the host around the call, especially when processing several entities. Do not reconstruct proofs, tokens, or private key material in diagnostic messages. A warning about a recommendation is distinct from a failed validation result; inspect the returned result before deciding whether the operation can continue.
Handle an operation result
The discovery example above checks result.ok before using authenticated metadata. Constructors and some host methods throw; protocol methods retain their documented failure results. Catch thrown failures at the application boundary and do not expose raw exceptions in HTTP responses. The return contracts describe each result shape.
Logger behavior and levels
Pass your logger in FederationOptions.logger to receive messages from core, authority, leaf, OIDC, and wallet operations. Logging is silent until you supply one. Each call passes a single message. Messages exclude JWTs, credentials, private keys, callback inputs, and raw exceptions. Synchronous exceptions and rejected promises from the logger are contained, leaving the operation's result, exception, or HTTP response unchanged.
Synchronous and asynchronous loggers are supported. The library handles returned promises without awaiting them, so a pending remote sink does not hold up protocol processing. Synchronous work inside your logger still runs inline.
Messages omit entity identifiers and structured context. In a collection traversal, a warning therefore does not identify the individual entity that triggered it. Use your application's operation correlation where needed.
The levels have these meanings:
debug: processing steps, cache decisions, candidate paths, and cancellation.info: completed operations and observable departures from applicable SHOULD or RECOMMENDED guidance.warn: rejected input or configuration that needs attention. Applicable MUST violations still cause normal rejection.error: unexpected service, storage, or application-callback failures, including verification timeouts.
Messages use the specification's terms where they apply. For example, a collection publisher without a Resolve endpoint receives one info notice after successful Entity Configuration signing: “Federation Entities publishing a federation_collection_endpoint SHOULD also publish a federation_resolve_endpoint.” Non-HTTPS Subordinate Event documentation produces a recommendation notice after its transaction commits. Omitting a MAY/OPTIONAL feature stays quiet.
Callback failures name the application integration, such as onRegistration or Wallet acceptance. Cache errors identify whether the read, write, or expired-entry deletion failed. Authority lifecycle completion messages follow successful commit. Continue handling returned errors and exceptions; a log message does not replace rejection or confirm that your callback performed every required check.
The specification determines which requirements apply; oidfed chooses these log levels, following node-oidc-provider's distinction between SHOULD notices and MUST warnings. Configure filtering and output in your host logger.
Logging cannot check application duties such as obtaining consent or scheduling trust refreshes. See operator and application responsibilities.
Core validation rejects a known Intermediate Entity or Trust Anchor whose checked Entity Configuration lacks federation_fetch_endpoint or federation_list_endpoint, following Federation §5.1.1. This is validation behavior even when no logger is supplied. Endpoint checks use the Entity Configurations available for validation; they do not require a trailing Trust Anchor Entity Configuration in a chain that otherwise permits its omission. Repeated paths to the same invalid authority produce one endpoint warning per resolution operation while retaining their individual errors. A later operation can report the problem again.
Handle remote protocol errors
Federation clients preserve recognized error codes. An unfamiliar syntactically valid OAuth error produces ERR_REMOTE_RESPONSE, with the responder's explanation in description and its code and HTTP status in remoteError. Treat those fields as remote input. Server-side public-error conversion maps this internal classification to a generic server error. Entity Collection §3.4.2 permits OAuth registry errors beyond the draft's named codes.