Repository navigation
feat(api): a coded message type, and the link test speaks it - #53
Merged
Merged
Conversation
Core sends the desktop app sentences to display. The app ships in
Simplified Chinese and English, so a sentence written here can only be
right in one of them — and this process serves the CLI and the server
edition too, neither of which has an interface language to consult.
`tw_types::Msg` is what goes over the wire instead: a stable code, the
arguments that fill the sentence, and the English text with those
arguments already in it. The app looks the code up in its own
dictionary; a code it does not know (core newer than the app, or a
third-party client with no dictionary at all) falls back to the English,
which beats showing a bare identifier. The code is the contract and the
sentence is not, so rewording costs nothing and only a change of meaning
takes a new code.
`msg!` builds one, binding the arguments before the format string so the
sentence and the argument map cannot drift apart:
msg!("l1.dns.no_records", host = host => "{host} resolved, but to no addresses.")
The link test is the first surface converted, and the one that shows why
the codes matter: it was comparing Chinese sentences to make decisions.
`resolve` asked `if e == timed_out()` to tell a DNS timeout from a DNS
failure, and `tcp_message` asked the same question a second time — both
one reworded character away from reporting the wrong thing, with nothing
to catch it. They compare `Msg::code` now.
Also here:
- `L1Result.error` and the two L1 `Stage`/`SkipReason` labels are
English; the labels were already documented as CLI-only, so the app
loses nothing.
- `Event::ProxyChanged` gains `failed: Option<L1Stage>` and its `detail`
becomes a `Msg`. It used to ship `"TCP 握手:{why}"` as one string, so
an app wanting to say it differently had to parse a sentence apart at
a colon.
- `twcore speed` prints English, and its segment column widens from 18
to 28 for "TLS handshake to the proxy".
- The tests that asserted on Chinese substrings assert on codes.
Not in this change: `tw_control::fail` still collapses a `Msg` to its
text for HTTP error bodies, so the `/proxies/test` 400 path loses the
code. That is the control plane's own error envelope, and it changes
with the rest of `tw-control`.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
fylorn
force-pushed
the
i18n/messages
branch
from
September 20, 2026 05:04
badfdab to
d6d8728
Compare
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.
Core sends the desktop app sentences to display. The app ships in Simplified
Chinese and English, so a sentence written here can only be right in one of
them — and this process serves the CLI and the server edition too, neither of
which has an interface language to consult.
tw_types::Msgis what goes over the wire instead: a stable code, the argumentsthat fill the sentence, and the English text with those arguments already in it.
The app looks the code up in its own dictionary; a code it does not know (core
newer than the app, or a third-party client with no dictionary at all) falls
back to the English, which beats showing a bare identifier. The code is the
contract and the sentence is not, so rewording costs nothing and only a change
of meaning takes a new code.
msg!builds one, binding the arguments before the format string so thesentence and the argument map cannot drift apart:
Why the link test went first
It is the surface that shows why the codes matter: it was comparing Chinese
sentences to make decisions.
tcp_messageasked the same question a second time. Both were one rewordedcharacter away from reporting the wrong cause, with no test and no compile error
to catch it. They compare
Msg::codenow.Also here
L1Result.erroris aMsg, and the twoStage/SkipReasonlabels areEnglish — they were already documented as CLI-only, so the app loses nothing.
Event::ProxyChangedgainsfailed: Option<L1Stage>, and itsdetailis aMsg. It used to ship"TCP 握手:{why}"as one string, so an app that wantedto phrase it differently had to take a sentence apart at a colon.
twcore speedprints English; its segment column widens from 18 to 28 to fit"TLS handshake to the proxy".
Not in this change
tw_control::failstill collapses aMsgto its text for HTTP error bodies, sothe 400 from
/proxies/testloses the code. That is the control plane's ownerror envelope and it changes with the rest of
tw-control.Verified
cargo fmt --all -- --check,cargo clippy --workspace --all-targets -- -D warnings,cargo test --workspace(78 suites, 0 failures) and./scripts/smoke.sh(51 passed, 0 failed) all green. The two new tests intw-typescover the argument map and that an empty one stays off the wire; thefour L1 tests that read error text now read codes.
🤖 Generated with Claude Code