Repository navigation
Description
Problem
When a v2 validation error names a limit, the limit exists only in the English detail text. Examples are "Keep the name under 100 characters." and "expected length <= 64". Clients that show their interface in another language translate a field error from its code (error.field.<code> in the shared translation catalog). They can't pull the number out of English text, so the translated message loses it. A Spanish administrator sees "This value isn't valid" where English says what the limit is.
This came up in review of #3894 (finding F1), where the web app's translated problem messages replace these details with the generic text for invalid. Every client that translates problem details has the same gap.
Proposal
An additive v2 change. A field error carries the values its message depends on as structured data, so each client can format a translated message with them:
{
"location": "body.name",
"code": "out_of_range",
"detail": "Keep the name under 100 characters.",
"params": { "max": 100 }
}paramsis an optional object onProblemError, keyed by name, with number or string values (max,min, andcountwhere it helps).detailstays as it is: English clients and older clients keep showing it.- A failure that today uses
invalidbut names a limit gets the code that describes it (out_of_range, or a narrower new code if the contract review prefers one), so the client picks the right message. - The shared catalog gets matching messages with placeholders, such as "Keep it under {max} characters", next to the existing
error.field.<code>texts.
Where v2 builds field errors
internal/apiv2/problem.go:ProblemError(location,code,detail).huma.NewErrorroutes schema-validation failures throughvalidationCodeandvalidationDetail. These map Huma's "expected length", "expected array length" and "expected number" messages toout_of_range. Huma'sErrorDetailhas onlymessage,locationandvalue, so the limit has to come from the operation's schema, or from Huma's message as a last resort.- About 105
ProblemErrorliterals in about 47 handler files, mostlycode: invalidwith an Englishdetailwritten in the handler or passed through from a service. For example,requestProblemininternal/apiv2/requests.gomaps everymediarequests.ValidationErrorfield toinvalid, with details such as "Keep the name under 100 characters." frominternal/requests/routes_admin.go. - Shared helpers:
validationProblemininternal/apiv2/home.go, and the per-domain*Problemmappers (groupProblem,adminSectionError,catalogProblem, and others) that turn service errors into field errors.
The schema-validation path covers most limits in one place. The handler-built errors that name a limit can move over one domain at a time.
Contract
- Additive under the pre-1.0 rules in
docs/architecture/api-contract.md: one new optional member onProblemError, and possibly newcodevalues. Clients must already tolerate unknown codes. - Advertise it with a capability flag, so a client knows when
paramscan appear, without version sniffing. /api/v1and jellycompat are unchanged.
Client follow-ups
Each client already translates field errors by code and falls back to detail. Each needs to read params and fill the matching catalog message:
- Web:
problemFieldDetailinweb/src/api/v2/request.ts(added in feat(web): translate v2 problem details #3894). - Android:
ServerText.ktinandroid-shared(common/i18n), on the translation stack. - Apple: the problem mapping in
APIv2Models.swift, on the translation stack. - Roku:
source/api/problem.bs, on the translation stack.
Related: #3894
AI disclosure: drafted by Claude Code (claude-opus-5-5) from the v2 source on main; the code references were checked against the source.
Activity