Skip to content
Security
Agent

error-formatting

<!-- Agent-consumed file. Keep terse, unambiguous, machine-parseable. -->

From plugin
jwx
2.4k9 skills9 agents

Claude Code

> /plugin marketplace add lestrrat-go/jwx
> /plugin install jwx-dev-v4@jwx-v4

Agent definition

error-formatting.md

<!-- Agent-consumed file. Keep terse, unambiguous, machine-parseable. -->

Error Handling

Pattern

Error types are defined directly in their respective packages. Use `errors.Is()` with a zero-value struct for type checks, and `errors.AsType[T]()` to extract structured fields:

// Type check (zero-value matching)
if errors.Is(err, jwt.TokenExpiredError{}) { ... }

// Extract structured detail
if expErr, ok := errors.AsType[jwt.TokenExpiredError](err); ok {
    log.Printf("expired at %s, checked at %s", expErr.Expiration, expErr.Now)
}

Within `jwt`, only `jwt.UnknownPayloadTypeError()` remains a sentinel function (no struct type).

Exported Error Types (jwt)

| Type | Structured Fields | Meaning | |------|------------------|---------| | `TokenExpiredError` | `Expiration`, `Now`, `Skew` | `exp` claim not satisfied | | `TokenNotYetValidError` | `NotBefore`, `Now`, `Skew` | `nbf` claim not satisfied | | `InvalidIssuedAtError` | `IssuedAt`, `Now`, `Skew` | `iat` claim not satisfied | | `InvalidIssuerError` | *(none)* | `iss` claim not satisfied | | `InvalidAudienceError` | *(none)* | `aud` claim not satisfied | | `ClaimValidationError` | `Claim`, `Expected`, `Actual` | Generic claim validator mismatch | | `TimeDeltaError` | `Claim1`, `Claim2`, `Value1`, `Value2`, `Delta`, `Limit`, `Skew` | Time delta out of range | | `ValidationError` | *(wraps inner)* | Blanket validation failure | | `ParseError` | *(wraps inner)* | Parse failed | | `MissingRequiredClaimError` | `Claim` | Required claim missing | | `ClaimNotFoundError` | `Name` | Claim not present (`jwt.Get` miss) | | `ClaimTypeMismatchError` | `Name`, `Got`, `Want` | Claim present but wrong type (`jwt.Get` type assertion failed) | | `ClaimAssignmentFailedError` | `Err` | Claim value assignment failed |

Exported Error Types (jwk)

| Type | Structured Fields | Meaning | |------|------------------|---------| | `KeyTypeMismatchError` | `Got`, `Want` (both `reflect.Type`) | Generic type parameter on `Import[T]` / `ParseKeyAs[T]` / `Export[T]` / `ExportAll[T]` does not match the value the function produced | | `UnknownKeyTypeError` | `KeyType` (string; empty when `kty` was missing) | Probe couldn't resolve `kty` to a known key family. Empty `KeyType` = `kty` field absent or non-string; populated = `kty` was a string but unrecognized | | `FieldNotFoundError` | `Name` | Field not present (`jwk.Get` miss) | | `FieldTypeMismatchError` | `Name`, `Got`, `Want` | Field present but wrong type (`jwk.Get` type assertion failed) |

Exported Error Types (jws)

| Type | Structured Fields | Meaning | |------|------------------|---------| | `FieldNotFoundError` | `Name` | Header field not present (`jws.Get` miss) | | `FieldTypeMismatchError` | `Name`, `Got`, `Want` | Header field present but wrong type (`jws.Get` type assertion failed) |

Exported Error Types (jwe)

| Type | Structured Fields | Meaning | |------|------------------|---------| | `MissingContentEncryptionError` | *(none)* | `enc` missing from protected headers during `Decrypt` | | `AlgorithmMismatchError` | `Expected`, `Got` (both `jwa.KeyEncryptionAlgorithm`) | Per-recipient/protected `alg` does not match the key's algorithm | | `FieldNotFoundError` | `Name` | Header field not present (`jwe.Get` miss) | | `FieldTypeMismatchError` | `Name`, `Got`, `Want` | Header field present but wrong type (`jwe.Get` type assertion failed) |

Sentinel Function Registry

| Package | Function | Meaning | |---------|----------|---------| | `jwt` | `UnknownPayloadTypeError()` | Unrecognized payload format | | `jws` | `SignError()` | Signing failed | | `jws` | `VerifyError()` | Verification process error | | `jws` | `VerificationError()` | Signature mismatch | | `jws` | `ParseError()` | Parse failed | | `jws` | `ErrCritPresent()` | `VerifyCompactFast` refused a `crit`-bearing protected header (use `jws.Verify`) | | `jws` | `ErrB64Present()` | `VerifyCompactFast` refused a `b64`-bearing protected header (use `jws.Verify`) | | `jws` | `ErrNonMinimalHeader()` | `VerifyCompactFast` refused a protected header outside the fast-path minimal shape — alg×1 (missing alg included) + optional single typ/kid/cty, no escapes/duplicates/extras (use `jws.Verify`) | | `jws` | `ErrUnclassifiableKey()` | Key classification failed at option time in `Sign`/`Verify` (Import failed, kty not registered, or key-agreement-only key like ecdh). Sentinel defined in `jws/internal/keyalg`; `jws.ErrUnclassifiableKey()` re-exports it | | `jwe` | `EncryptError()` | Encryption failed | | `jwe` | `DecryptError()` | Decryption failed | | `jwe` | `HPKEError()` | HPKE encrypt/decrypt operation failed | | `jwe` | `RecipientError()` | Recipient processing error | | `jwe` | `ParseError()` | Parse failed | | `jwk` | `ImportError()` | Key import failed | | `jwk` | `ParseError()` | Key parse failed | | `jwk` | `ContinueError()` | Skip key (used by parsers) | | `jwa` | `ErrInvalidKeyAlgorithm()` | Invalid algorithm |

Error Helpers

  • `jwk.IsKeyValidationError(err error) bool` — returns `true` if `err` indicates a key validation failure.

Collect-All Validation Errors

By default, `jwt.Validate()` returns on first failure (v3 behavior). Use `jwt.WithCollectErrors(true)` to gather all validation errors:

err := jwt.Validate(token, jwt.WithIssuer("x"), jwt.WithCollectErrors(true))
// err wraps all failures via errors.Join; each cause is reachable via errors.Is / errors.AsType

JWE Key Provider Failures

`jwe.Decrypt` continues to later key providers after a `FetchKeys` error. If all attempts fail, provider errors and per-key errors are joined (subject to `decryptErrorJoinCap`) and remain reachable via `errors.Is` / `errors.AsType`. Context cancellation stops attempts immediately, including after `FetchKeys`. If no provider supplies a candidate and there are no underlying errors, the failure reports zero attempted keys without wrapping a nil error.

Error Wrapping

Errors wrap typed errors with `fmt.Errorf("cont

Read more
@lestrrat-go
Ships withjwx

Go module implementing various JWx (JWA/JWE/JWK/JWS/JWT, otherwise known as JOSE) technologies. If you are using this module in your product or your company, please add your product and/or company name in the Wiki! It really helps keeping up our motivation.

2.4k2 skills9 agents
Get the whole plugin

Stars on GitHub

Momentum

stars in total
2.4k
Star history of lestrrat-go/jwx on GitHub, a chart by star-history.com

Other agents on jwx.

companion-template-sync

companion-template-syn…

Agent

Pull newest GitHub Actions versions from companion repos back into `.companions/templates/`. Dependabot updates each companion…

@lestrrat-go@lestrrat-goInstall Agent
companions

companions

Agent

Extension modules under `github.com/jwx-go/*` (asmbase64, compsig, ed448, es256k, examples, jwkfetch, jwxfilter, jwxmigrate,…

@lestrrat-go@lestrrat-goInstall Agent
internals

internals

Agent

<!-- Agent-consumed file. Keep terse, unambiguous, machine-parseable. -->

@lestrrat-go@lestrrat-goInstall Agent
packages

packages

Agent

<!-- Agent-consumed file. Keep terse, unambiguous, machine-parseable. -->

@lestrrat-go@lestrrat-goInstall Agent
release

release

Agent

How to release a new version on a `develop/v*` → `v*` line (e.g. v3.1.0). Assumes all code and changelog entries are already on…

@lestrrat-go@lestrrat-goInstall Agent

More agents from other plugins.

dependency-review

dependency-review

Agent

<!-- SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. --> <!--…

@nvidia@nvidiaInstall Agent
0-preflight

0-preflight

Agent

Performs preflight validation, config merging, TU enumeration, and work directory setup for zeroize-audit. Produces…

skills10d8.2k
@trailofbits@trailofbitsInstall Agent
autopilot

autopilot

Agent

Autonomous hunt loop agent. Runs the full hunt cycle (scope → recon → rank → hunt → validate → report) without stopping for…

@awarexone@awarexoneInstall Agent
autopilot

autopilot

Agent

Autonomous hunt loop agent. Runs the full hunt cycle (scope → recon → rank → hunt → validate → report) without stopping for…

@shuvonsec@shuvonsecInstall Agent

Questions about error-formatting.

Which coding agents can use error-formatting?
error-formatting installs in Claude Code and Cursor: each loads subagents from .claude/agents, so copy the file there. Flowy's auto-invocation runs in Claude Code only.