feat: add WithPlatformCode for domain-level error identity
Adds an optional PlatformCode field to *Err, decoupled from the transport-level Code. Code drives HTTP/gRPC status mapping; PlatformCode is a stable domain identifier for consuming applications (e.g. a frontend performing i18n) to map errors to localised messages. Platform codes are optional — errors without a user-actionable meaning (500s, infrastructure failures, auth rejections) carry none. Fully backwards-compatible: no existing signatures or JSON output changed for errors without a platform code. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
16
CHANGELOG.md
16
CHANGELOG.md
@@ -5,6 +5,22 @@ All notable changes to this module will be documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this module adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [0.10.0] - 2026-03-25
|
||||
|
||||
### Added
|
||||
|
||||
- `(*Err).WithPlatformCode(code string) *Err` — chainable builder method to attach a platform-level error code; returns the receiver for chaining
|
||||
- `(*Err).PlatformCode() string` — getter that returns the platform code, or an empty string if none was set
|
||||
- `platformCode` field in `MarshalJSON` output — serialised as `"platformCode"` and omitted when empty (`omitempty`)
|
||||
|
||||
### Design Notes
|
||||
|
||||
- Platform codes operate at the domain/system layer and are intentionally decoupled from the transport-level `Code`. `Code` drives HTTP status mapping and gRPC status codes; `PlatformCode` is a stable semantic identifier for the consuming application (e.g. a frontend performing i18n).
|
||||
- Platform codes are **optional**. Errors that do not have a user-actionable meaning (500 internal errors, infrastructure failures, authentication rejections) should not carry one.
|
||||
- No existing behaviour changed — `Code`, `Error`, `Unwrap`, `WithContext`, `MarshalJSON` (for errors without a platform code) are all backwards-compatible.
|
||||
|
||||
[0.10.0]: https://code.nochebuena.dev/go/xerrors/compare/v0.9.0...v0.10.0
|
||||
|
||||
## [0.9.0] - 2026-03-18
|
||||
|
||||
### Added
|
||||
|
||||
Reference in New Issue
Block a user