Repository navigation
Typed ErrorKind: classify vendor codes once, convert all domain modules, CLI exit codes (#62) - #64
Merged
Merged
Conversation
163 of 168 Result signatures return Result<_, String>, so every vendor rejection, expired session and network timeout funnels into the same Chinese prose string - and the web console turns all of them into the same response, with no kind field to branch on. First step of IRmsk#62: introduce src/error.rs with ErrorKind (Auth / Protocol{code,msg} / Network / RateLimit / Fence / Client / Storage / Json), one classify_vendor() as the single place a vendor business code becomes a category (10121/10175 -> Auth, 10603 -> RateLimit, others -> Protocol), and http_status()/kind_name() mappings. Client extends the issue sketch with a Client variant for local construction failures (clock, keys, unsupported method) - those are not network problems. Converted in this step: client.rs (request/expect_ok classify at the boundary), login / records / semester / cheat / ai, and the web routes backed by them now answer with precise statuses (401 auth / 429 rate limit / 502 upstream) plus structured kind and vendor_code fields. flow/submit/fence/points/policy/obs keep String signatures with an explicit to_string() boundary and TODO(IRmsk#62) markers; they convert next. Vendor-facing behavior is unchanged (same requests, same retry triggers). Console HTTP responses intentionally change for these endpoints - that is the point of IRmsk#62 - and CLI printed wording shifts slightly; exit codes are untouched (step 3 of the rollout). Verified live: a real vendor rejection (10175 wrong password, from a smoke run against the actual server) surfaces as 502 + kind=protocol + vendor_code=10175, and is now classified Auth in classify_vendor.
Owner
|
合了:0302b87。 我在本地把它和 main 上刚加的 unwrap/expect/panic 禁令(a855ad5)合起来跑了一遍:fmt、clippy、555 个测试、cargo-deny 都过,没有一处需要改你的代码。 顺手核了一个你没提的点:前端
|
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.
Closes #62.
Summary
Replaces
Result<_, String>across the domain layers with a typedErrorKind, completing all three steps of the issue's rollout:Type (
src/error.rs):Auth/Protocol{code, msg}/Network/RateLimit/Fence/Client/Storage(io)/Json(serde)/Other, Chinese explanations asDisplay. One extension of the issue sketch:Clientcarries local request-construction failures (clock skew, missing device keys, unsupported method) — folding those intoNetworkwould mislabel "系统时间异常" as a network problem.Other(String)is the documented migration tail for local data-shape messages not yet assigned a specific variant; the known semantics (vendor codes, geometry, IO, auth) all live in concrete variants.Step 1 — classification at the choke point:
client.rs(request + expect_ok) classifies once:10121/10175→ Auth,10603→ RateLimit, others → Protocol; transport failures → Network.classify_vendoris the only place a vendor business code becomes a category.Step 2 — all domain modules converted: client, login, records, semester, cheat, ai, flow, submit, fence, points, policy, obs, gmttime, gt4, gt4image, session, accounts, guard, start_time, egress, audit, crosscheck, device_table + track (roadnet, tileroad, fence_route, planner, simulate).
Result<_, String>is zero acrosssrc/api/andsrc/track/; every transition shim from the first step is removed. The web layer keepsResult<(), String>for its own plumbing — those are tiny_http response-write failures, not domain errors (documented in the module docs).Step 3 — consumers:
json_err_kind: precise statuses (401 auth / 429 rate-limit / 502 upstream) plus structuredkindandvendor_codefields.ErrorKind::exit_code()maps each variant to a distinct code 10–18 (10 auth, 11 protocol, 12 network, 13 rate limit, 14 fence, 15 local construction, 16 storage, 17 json, 18 other), chosen not to collide with the existing 0/1/2/3; typed error paths inmain.rsexit with their class, so scripts branch on exit codes instead of parsing Chinese prose.Behavior
kind/vendor_code. Documented in CHANGELOG.Verification
cargo clippy --all-targets0 warnings,fmt --checkclean, compliant with the Proposal: workspace lint baseline (unsafe forbid, missing_docs, clippy::pedantic + cast denies) #58 lint baseline.-10000cluster-fault guidance asserted verbatim (survives asProtocol{code:-10000}with the full "别折腾本地环境" explanation);10121assertsAuthinstead of a substring contract.10175→ HTTP 401 +kind=auth+ structured Chinese message; that code was added toclassify_vendorwith a test.auditon a missing file still exits 1,versionexits 0.