Adds WithPlatformCode / PlatformCode() to *Err — an optional domain-level error identifier that is fully decoupled from the transport-level Code.
Why two codes?
Field
Layer
Purpose
Code
Transport
Maps to HTTP status / gRPC status. Stable, bounded (NOT_FOUND → 404).
PlatformCode
Domain/Platform
Identifies the specific domain error (EMPLOYEE_NOT_FOUND). Open-ended, consumer-defined.
A NOT_FOUND transport code cannot tell a frontend whether an employee, a role, or a branch was missing — it falls back to a generic message. PlatformCode gives the frontend the exact signal it needs to render a specific translated message, without the backend carrying any locale-specific copy.
Platform codes are optional. Errors without a user-actionable meaning (500 internals, infrastructure failures, auth rejections) carry none.
## Summary
Adds `WithPlatformCode` / `PlatformCode()` to `*Err` — an optional domain-level error identifier that is fully decoupled from the transport-level `Code`.
**Why two codes?**
| Field | Layer | Purpose |
|-------|-------|---------|
| `Code` | Transport | Maps to HTTP status / gRPC status. Stable, bounded (`NOT_FOUND` → 404). |
| `PlatformCode` | Domain/Platform | Identifies the specific domain error (`EMPLOYEE_NOT_FOUND`). Open-ended, consumer-defined. |
A `NOT_FOUND` transport code cannot tell a frontend whether an employee, a role, or a branch was missing — it falls back to a generic message. `PlatformCode` gives the frontend the exact signal it needs to render a specific translated message, without the backend carrying any locale-specific copy.
**Platform codes are optional.** Errors without a user-actionable meaning (500 internals, infrastructure failures, auth rejections) carry none.
## Changes
- `(*Err).WithPlatformCode(code string) *Err` — chainable builder
- `(*Err).PlatformCode() string` — getter (empty string if not set)
- `MarshalJSON` includes `"platformCode"` when set, omits otherwise (`omitempty`)
- 6 new tests covering: set+get, empty default, chaining, JSON include/omit
## Backwards compatibility
Fully additive — no existing signatures, behaviour, or JSON output changed for errors that don't use `WithPlatformCode`.
## Test plan
- [x] `go test ./...` passes
- [x] `platformCode` present in JSON when set
- [x] `platformCode` absent from JSON when not set
- [x] Chaining with `WithContext` and `WithError` works correctly
- [x] `Code()` unaffected by `WithPlatformCode`
🤖 Generated with [Claude Code](https://claude.com/claude-code)
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>
Rene Nochebuena
approved these changes 2026-03-25 16:42:07 -06:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Summary
Adds
WithPlatformCode/PlatformCode()to*Err— an optional domain-level error identifier that is fully decoupled from the transport-levelCode.Why two codes?
CodeNOT_FOUND→ 404).PlatformCodeEMPLOYEE_NOT_FOUND). Open-ended, consumer-defined.A
NOT_FOUNDtransport code cannot tell a frontend whether an employee, a role, or a branch was missing — it falls back to a generic message.PlatformCodegives the frontend the exact signal it needs to render a specific translated message, without the backend carrying any locale-specific copy.Platform codes are optional. Errors without a user-actionable meaning (500 internals, infrastructure failures, auth rejections) carry none.
Changes
(*Err).WithPlatformCode(code string) *Err— chainable builder(*Err).PlatformCode() string— getter (empty string if not set)MarshalJSONincludes"platformCode"when set, omits otherwise (omitempty)Backwards compatibility
Fully additive — no existing signatures, behaviour, or JSON output changed for errors that don't use
WithPlatformCode.Test plan
go test ./...passesplatformCodepresent in JSON when setplatformCodeabsent from JSON when not setWithContextandWithErrorworks correctlyCode()unaffected byWithPlatformCode🤖 Generated with Claude Code
LGTM