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.Messagemay name a table, a host, or a driver failure, andDetailsis rendered as the problem document’sdetail, so every mapper —MapServiceToHandlerError,MapRepoToServiceError,MapInfraToServiceError,MapToApplicationError— was forwarding internal text to clients. OnlyDetailscrosses a boundary now; the original error stays reachable throughUnwrapfor the logs. HANDLER_METHOD_NOT_ALLOWED,HANDLER_TOO_MANY_REQUESTS,HANDLER_NOT_IMPLEMENTED, andHANDLER_SERVICE_UNAVAILABLEhave registered user messages. Without one,New(code, message)fell back to the developer message it was given, which put that string in the problem’stitle.- 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, andRegisteredErrors, over the layer-neutralCustomErrortype. 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. GetAllErrorslists registered codes, so the catalog covers the codes the process actually answers for rather than only the static tables.numeric_codein the problem document: the registry’s numeric code for the failure, as a JSON number, alongside the stringcode. A client can switch on4004or 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, andValidateRegistrynow reports that case so it fails at startup instead.- RFC 9457 §3.2 extension members:
(*AppError).WithExtension,Problem.Extensions, andProblem.WithExtension. Extensions are rendered as top-level members of the document, a reserved member name is refused rather than allowed to overwritestatusorcode, andProblemnow round-trips throughencoding/jsonwith its extensions intact. - Per-request localization:
WithLanguage,LanguageFromContext,NegotiateLanguage(q-values, subtag matching), andSupportedLanguages.SetProblemLanguageremains the per-process default. - Context-aware and request-aware writers:
(*AppError).ProblemCtx,WriteProblemCtx,WriteProblemRequest,WriteResultCtx, andWriteResultRequest. They localize the title and echo the context’s request ID as arequest_idmember — including for errors that never passed through errorx, whose text is still dropped. retryablein the problem document: whether repeating the request can succeed, from the same registry policyRetryWithBackoffreads. 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 asretryable, 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, andJSONMediaType. 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 toWriteProblem. -
RFC 9457 problem details as the HTTP response format:
Problem,(*AppError).Problem(instance),WriteProblem,ProblemMediaType,SetProblemBaseURI, andSetProblemLanguage.WriteProblemwrites the status,Content-Type: application/problem+json, and a body carrying no internal detail; an error that is not anAppErrorbecomes an opaque 500 rather than having its text forwarded to the client. - Application layer:
APP_*codes (90xx),NewApplicationError,WrapApplicationError,MapToApplicationError, andLayerApplication. - Infrastructure layer:
INFRA_*codes (91xx),NewInfraError,WrapInfraError,MapInfraToServiceError,IsInfraError, andLayerInfrastructure. - Domain layer:
DOMAIN_*codes (8xxx),NewDomainError,WrapDomainError,IsDomainError, andLayerDomain, 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.MapDomainToServiceErrornow also accepts anAppErrorthat already carries a domain-layer code.RegisterDomainCode/RegisterDomainCodesso applications register their own business error codes against the registry.DomainErrorinterface, letting domain packages be recognized byMapDomainToServiceErrorwithout 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. NewandWrapresolve 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’stitle.RegisterDomainCodeandRegisterDomainCodesremain as the unvalidated older names for the same table.AppErrornow marshals to RFC 9457 problem details instead of to its Go field names. The wire format is decoupled from the struct: renaming anAppErrorfield no longer changes what clients parse, and an internal field added later cannot leak by default. Payload keys change fromType/HTTPStatus/UserMsgtocode/status/title, andSeverity,Category, andSuggestionare 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.
MapServiceToHandlerErrorwraps the incoming error instead of replacing it, so the cause stays reachable througherrors.Isfor logging.MapToServiceErrordispatches onGetLayerrather than on code prefixes.- Layer mapping never mutates the error it was given.
MapServiceToHandlerErrorused 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. MapRepoToServiceErrorwraps the repository error instead of rebuilding it, soerrors.Isstill finds the cause and the log still shows what the driver said.WriteJSONtreats a nil pointer as no content (204) rather than encodingnull, and renders a nil slice or map as[]or{}rather thannull.- Driver adapters moved to their own packages under
./adapter, each exposing a uniformHandleError. Importing the root package no longer pulls in pgx, go-redis, or MinIO. - Alert delivery moved to
./reporter/webhookand./reporter/alerter. - Error persistence moved to
./logwriter.
Removed
- Application-specific business error codes; register your own instead.