Repository navigation
feat: give core's own error sentences their own codes - #143
Merged
Merged
Conversation
Fourteen control-plane codes (and l1.io) were pure passthrough wrappers:
the template was "{detail}" and the detail was the Display of some core
error, so a translated UI still showed English. Each of those errors now
carries its own coded Msg instead.
- tw-yaml PatchError, tw-engine RouteError/MatchError, tw-pricing
SheetError, tw-config CredentialError/StoreError/EditError/
ValidationError, tw-adopt PlanError/ForeignError/McpError and
tw-control RefreshError get a msg() with one code per variant; their
Display is that Msg's text, so the English is written once.
- tw_config::Rejected carries a Msg: semantic errors speak with their
own code, serde's words get a coded frame (stage and line).
- ApplyError keeps each cause's Msg (Invalid/InUse/BadPath/Build carry
one) instead of an English string, so route, group, key and resource
validation reaches the UI with its own code.
- l1 maps the common io::ErrorKinds to codes; l1.io with {detail}
remains only for the rest.
- Truly external text (SQLite, serde, reqwest, OS) keeps a detail arg
inside a coded sentence.
Removed codes: control.adopt_failed, control.bad_credential,
control.bad_price_sheet, control.bad_rule, control.config_rejected,
control.internal, control.listen.bad_bind, control.mcp_failed,
control.mcp_target_unknown, control.pricing_refresh_failed,
control.route_failed, control.upstream_call_failed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Fourteen codes were pure passthrough wrappers: the English template was
"{detail}"anddetailwas theDisplayof some core error. The UI could only translate the code, which said nothing, so the Chinese UI showed the English sentence underneath. Worse, several paths flattened an already-codedMsgback into text (invalid(e.text),client_for(...).map_err(|e| e.message()), the price-sheet draft double wrap) before wrapping it again.What changed
Core's own sentences now carry their own codes. Each error enum gets a
msg()with onemsg!per variant, next to its definition; itsDisplayis#[error("{}", self.msg())], so the English is written exactly once.detailwascontrol.adopt_failed,control.mcp_failed,control.mcp_target_unknowntw_adoptPlanError/ForeignError/McpErroradopt.plan.*,adopt.file.*,adopt.mcp.*; an unverified MCP target speaks with its existing reason codecontrol.bad_credentialCredentialErrorconfig.credential.*control.bad_price_sheetSheetError(or an already-coded name error)pricing.sheet.*, or the name error as iscontrol.bad_rule,control.route_failedroutes::to_rulestrings,RouteErrorcontrol.rule.*(every one names the rule),engine.*,engine.compare.*control.config_rejectedApplyError: store, validation, edit, patch, in-use and the flattened resource errorsconfig.store.*,config.*(validation),config.edit.*,yaml.*,control.*_in_use,control.group.*,control.patch.*,control.config_stale, …ApplyErrorgainsInvalid(Msg);InUse/BadPath/Buildcarry aMsgcontrol.listen.bad_bindBind's own serde messagecontrol.listen.bind_invalidcontrol.pricing_refresh_failedRefreshErrorbuilt fromformat!control.pricing.*control.upstream_call_failedGatewayErrortext, a serde error, Z.ai call stringsgw.*Msg;control.device_code_unreadable;control.account_service_*control.internalStoreErrorcontrol.records_unreadable,control.internal_error,config.store.*l1.iostd::io::Errorl1.io.refused,.reset,.aborted,.timed_out,.addr_not_available,.not_found,.permission_denied,.eof,.broken_pipe,.host_unreachable,.network_unreachable.l1.iostays as the fallback for other kinds.tcp_messagenow decides by code, not by the OS wordingText from outside (SQLite, serde, regex, reqwest, the OS, an upstream's body) stays in a
detailarg inside a coded sentence.tw_config::Rejectedcarries aMsg: semantic errors use their own code, and serde's words get a coded frame (config.rejected/config.rejected_atwithstageandline). TheConfigRejectedevent keeps sending the text.Two nested cases keep the inner code and add one arg, rather than doubling the code table:
ValidationError::Credentialaddsupstreamto the credential code, and a comparison error inside a route rule addsruleto theengine.compare.*code. In both cases the English text gets the matching prefix.Small cleanups found along the way:
PlanError::SecretGonewas never constructed and is gone;BadCidrand the empty-pattern case no longer carry a fixed Englishreason/detailstring.HTTP status codes are unchanged.
Remaining
{detail}-only codesl1.io: io kinds other than the eleven above (raw OS text)config.unparsable: serde's message insideRejected. It only reaches the UI through theconfig.rejected*frame (and as text in theConfigRejectedevent)config.credential.env:${VAR}expansion failures. These happen only at forward time, never in the credential checks that produce a MsgTests
Every converted enum has a test that each variant yields its own non-empty code, unique within the enum, whose text equals
Display. Wrapped variants are checked to use the inner code.to_rule/to_groupfailures, io kind mapping,tcp_messageandCallErrorare covered too.Checked locally:
cargo fmt --all --check,cargo clippy --all-targets -- -D warnings,cargo clippy -p <touched> --lib -- -D warningsandcargo test --workspace.🤖 Generated with Claude Code