Repository navigation
feat(ts): translate str::from_utf8 and Utf8Error - #159
Conversation
Quest-Claim: 739e227efa79db49
`str::from_utf8` decodes with the fatal `TextDecoder` and, on failure, reports std's `valid_up_to` and `error_len`. `Utf8Error` is its own runtime type, which `FromUtf8Error` now holds as std's does, so both share one `Display` and `Debug`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 5d5abe4
No actionable bugs found in the changed code. The direction is sound: reuse the fatal decoder and existing UTF-8 error scan, share error formatting between borrowed and owned decoding, and document the runtime representation change rather than maintain duplicate error logic. The differential fixtures cover offsets, BOM preservation, invalid boundary sequences, truncation, and formatting.
Verification limits: static review of the diff and relevant runtime/lowering code through GitHub; I did not run the translator, differential tests, or consumer build.
# Conflicts: # ts/fixtures/lang/src/harness.rs # ts/fixtures/lang/src/lib.rs
# Conflicts: # quest/m1/ts-utf8.md # ts/fixtures/lang/caller.ts
Main's ops 55 and 56 keep their numbers; utf8::decodes moves to 57.
|
Merge summary:
(Written by Claude Opus 5.5) |
Problem
moq-dev/moq#6843 makes moq-net's
Decoder::strcallstd::str::from_utf8, sojust ts moqat the moq revision #144 moves to (c764ace) refusesstd::str::from_utf8andstd::str::Utf8Error. Finishesquest/m1/ts-utf8.md.Consumer: moq-net's
coding::Decoder::str, andsetup::decode_implementationand the like.Approach
str::from_utf8(bothcore::str::from_utf8andstr's own) isrt.strFromUtf8: the fatalTextDecoderon a view of the slice, which rejects exactly what std rejects (surrogates, overlongs, past U+10FFFF, truncated), keeping a leading BOM as std does.valid_up_toanderror_lenfrom the scanString::from_utf8already used.Utf8Errorisrt.Utf8Error, a plain{ validUpTo, errorLen };valid_up_toanderror_lenread its fields;DisplayandDebugare runtime functions.rt.FromUtf8Errornow holds anrt.Utf8Erroras std's does, so the two share oneDisplayandDebug.langop,utf8::decodes, decodes from every offset of raw bytes or of an alphabet of UTF-8 boundary bytes and printsvalid_up_to,error_len,Display,Debug, and{:#?}.caller.tsadds named cases for the BOM, surrogates, overlongs, past U+10FFFF, and truncations at the end or cut by another byte. Mutation-checked: widening the surrogate range in the runtime yields 51 differences.Impact
std::str::from_utf8,str::from_utf8,Utf8Error::{valid_up_to, error_len}, andUtf8Error'sDisplay/Debugnow translate instead of being refused.rt.FromUtf8Error'svalidUpToanderrorLenmove toe.error.validUpToande.error.errorLen(MIGRATE.md entry). New exports:Utf8Error,strFromUtf8,fmtUtf8ErrorDebug,fmtUtf8ErrorDisplay.Alternatives
FromUtf8Error's flat fields and duplicate theDebug: dropped for one shared representation matching std's.Checks
just check: pass.just ts test: pass (unit, fixtures incl.langdifferential, runtime).just ts moq target/moqat c764ace: pass (translate +tsc). The pin itself stays at 88448d9; feat(ffi): export moq's owned Path #144 moves it.just ffi/driver/uniffi test(untouched).Follow-ups
just ts censusat c764ace still panics invec_view; that isquest/m1/ts-vec-view.md, still needed before feat(ffi): export moq's owned Path #144 merges.🤖 Generated with Claude Code
(Written by Claude Opus 5.5)