Changelog

All notable changes to this project are documented here. The format follows Keep a Changelog and this project adheres to Semantic Versioning.

Unreleased

0.1.0 - 2026-09-17

First tagged release. The API is not frozen: v0 means a later minor version may change it, and the layer mapping and response shape are where that is most likely.

Security

  • Layer mappers no longer copy the developer message into Details. Message may name a table, a host, or a driver failure, and Details is rendered as the problem document’s detail, so every mapper — MapServiceToHandlerError, MapRepoToServiceError, MapInfraToServiceError, MapToApplicationError — was forwarding internal text to clients. Only Details crosses a boundary now; the original error stays reachable through Unwrap for the logs.
  • HANDLER_METHOD_NOT_ALLOWED, HANDLER_TOO_MANY_REQUESTS, HANDLER_NOT_IMPLEMENTED, and HANDLER_SERVICE_UNAVAILABLE have registered user messages. Without one, New(code, message) fell back to the developer message it was given, which put that string in the problem’s title.
  • Problem and JSON responses carry X-Content-Type-Options: nosniff.

Added

  • Custom error codes are a first-class, validated API: RegisterError, RegisterErrors (atomic — one bad definition registers none of the batch), MustRegisterError, MustRegisterErrors, UnregisterError, IsRegistered, LookupError, and RegisteredErrors, over the layer-neutral CustomError type. A definition that the registry could not answer for is rejected at registration — empty code, non-integer numeric code, a numeric code already claimed by another code, missing English message, impossible HTTP status, a retry policy that contradicts itself — instead of surfacing on the first request that hits it. Zero fields default to status 500, SeverityMedium, CategorySystem, and the layer implied by the code prefix.
  • GetAllErrors lists registered codes, so the catalog covers the codes the process actually answers for rather than only the static tables.
  • numeric_code in the problem document: the registry’s numeric code for the failure, as a JSON number, alongside the string code. A client can switch on 4004 or range over a block without parsing. It is omitted rather than sent as a string when a code’s registered numeric is not an integer, and ValidateRegistry now reports that case so it fails at startup instead.
  • RFC 9457 §3.2 extension members: (*AppError).WithExtension, Problem.Extensions, and Problem.WithExtension. Extensions are rendered as top-level members of the document, a reserved member name is refused rather than allowed to overwrite status or code, and Problem now round-trips through encoding/json with its extensions intact.
  • Per-request localization: WithLanguage, LanguageFromContext, NegotiateLanguage (q-values, subtag matching), and SupportedLanguages. SetProblemLanguage remains the per-process default.
  • Context-aware and request-aware writers: (*AppError).ProblemCtx, WriteProblemCtx, WriteProblemRequest, WriteResultCtx, and WriteResultRequest. They localize the title and echo the context’s request ID as a request_id member — including for errors that never passed through errorx, whose text is still dropped.
  • retryable in the problem document: whether repeating the request can succeed, from the same registry policy RetryWithBackoff reads. It is present only when true, so its absence means do not retry, and it saves a client from guessing at a status that cannot tell a transient deadlock from a nil map.
  • Retry-After: sent whenever the code’s registered retry policy marks the code retryable and names a delay — the same source as retryable, so header and body cannot disagree — or explicitly via (*AppError).WithRetryAfter. The status does not gate it: a retryable 504 carries a delay as much as a 503.
  • Success response writers, so both halves of an HTTP response come from one package: WriteJSON, WriteOK, WriteCreated, WriteNoContent, WriteResult, and JSONMediaType. Payloads are written unwrapped; a nil payload becomes 204; a payload that fails to encode leaves the response untouched so the handler can still fall back to WriteProblem.
  • RFC 9457 problem details as the HTTP response format: Problem, (*AppError).Problem(instance), WriteProblem, ProblemMediaType, SetProblemBaseURI, and SetProblemLanguage. WriteProblem writes the status, Content-Type: application/problem+json, and a body carrying no internal detail; an error that is not an AppError becomes an opaque 500 rather than having its text forwarded to the client.

  • Application layer: APP_* codes (90xx), NewApplicationError, WrapApplicationError, MapToApplicationError, and LayerApplication.
  • Infrastructure layer: INFRA_* codes (91xx), NewInfraError, WrapInfraError, MapInfraToServiceError, IsInfraError, and LayerInfrastructure.
  • Domain layer: DOMAIN_* codes (8xxx), NewDomainError, WrapDomainError, IsDomainError, and LayerDomain, completing the per-layer wrapper set alongside repository, service, and handler.
  • DomainCode.Layer, so a registered code states its own layer instead of relying on the code prefix.
  • MapDomainToServiceError now also accepts an AppError that already carries a domain-layer code.
  • RegisterDomainCode / RegisterDomainCodes so applications register their own business error codes against the registry.
  • DomainError interface, letting domain packages be recognized by MapDomainToServiceError without importing errorx.

Changed

  • The registry tables are guarded by a mutex, so registering a code is safe concurrently with error construction rather than racing every New.
  • New and Wrap resolve a registered code’s user message when no static table answers for it. Previously a custom code fell through to the developer message it was handed, which put an internal string in the problem’s title.
  • RegisterDomainCode and RegisterDomainCodes remain as the unvalidated older names for the same table.
  • AppError now marshals to RFC 9457 problem details instead of to its Go field names. The wire format is decoupled from the struct: renaming an AppError field no longer changes what clients parse, and an internal field added later cannot leak by default. Payload keys change from Type/HTTPStatus/UserMsg to code/status/title, and Severity, Category, and Suggestion are no longer sent to clients — they are internal taxonomy.
  • Infrastructure and repository codes are now always translated at the transport boundary instead of being passed through when they carried a registered HTTP status, so driver detail cannot reach a client.
  • MapServiceToHandlerError wraps the incoming error instead of replacing it, so the cause stays reachable through errors.Is for logging.
  • MapToServiceError dispatches on GetLayer rather than on code prefixes.
  • Layer mapping never mutates the error it was given. MapServiceToHandlerError used to write the registered status onto the caller’s error, which a second goroutine could be reading; it now returns a copy when the status has to change, and the same error otherwise.
  • MapRepoToServiceError wraps the repository error instead of rebuilding it, so errors.Is still finds the cause and the log still shows what the driver said.
  • WriteJSON treats a nil pointer as no content (204) rather than encoding null, and renders a nil slice or map as [] or {} rather than null.
  • Driver adapters moved to their own packages under ./adapter, each exposing a uniform HandleError. Importing the root package no longer pulls in pgx, go-redis, or MinIO.
  • Alert delivery moved to ./reporter/webhook and ./reporter/alerter.
  • Error persistence moved to ./logwriter.

Removed

  • Application-specific business error codes; register your own instead.