Repository navigation
Name the field or index in Rust JSG struct field and array element errors - #8632
Conversation
There was a problem hiding this comment.
Superseded by the review of
f2b0c834.
This review, of b9e89302
✅ Approved — No issues found: the field and index messages match C++ JSG's, errors thrown during conversion still pass through unchanged, and the new messages are covered by tests.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No issues found. The error messages hold only compile-time field and class names and numeric indexes. A value of the wrong type is still rejected.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
No issues found.
⚡ Performance: ✅ LGTM
No issues found.
📝 Documentation: ✅ LGTM
No issues found.
Reviewed commit: b9e89302
guybedford
left a comment
There was a problem hiding this comment.
Looks good. I checked that every try_from_js override accepts exactly what its from_js does, so this only changes messages, and the three messages match typeErrorMessage() in jsg/util.c++. A few nits inline, none blocking.
…rors
A `#[jsg_struct]` field or a `Vec` element of the wrong type failed with the error of the
inner conversion, without saying where: `{ list: 1 }` gave "Expected Array but got number".
C++ JSG names the field or the index: "Incorrect type for the 'list' field on 'Outer': the
provided value is not of type 'Array'." and "Incorrect type for array element 1: ...". In a
differential run of the same values through C++ and Rust methods, this made about 70 of 100
message diffs.
In this patch the struct macro and `Vec::try_from_js` convert with `try_from_js` and report a
value that isn't of the type with C++ JSG's message, the way `Dict` entries and method
arguments already do. An error thrown while converting passes through unchanged. The README
also notes two differences that stay: a Rust `String` is a USVString, so a lone surrogate
comes back as one U+FFFD where C++ JSG's WTF-8 `kj::String` gives three, and `Vec`
conversion follows the array's current length when script shortens it.
b9e8930 to
f2b0c83
Compare
There was a problem hiding this comment.
✅ Approved — No issues found: the approver's three nits are fixed, the field, index and argument messages are built in one place and match C++ JSG, and errors thrown during conversion still pass through unchanged.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No issues found. The messages contain only compile-time field and class names, numeric indexes, and the Dict key, which earlier messages already included. A value of the wrong type is still rejected.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
No issues found. The try_from_js doc, the method-argument message (now TypeErrorContext::MethodArgument) and the single source for the field name are all fixed at this commit. These paths behave correctly: Option fields, Vec holes and length changes, and coercing primitives.
⚡ Performance: ✅ LGTM
No issues found. Messages are built only when conversion fails (#[cold]). A nested struct now checks the value's type once instead of twice.
📝 Documentation: ✅ LGTM
No issues found.
Reviewed commit: f2b0c834
When a
#[jsg_struct]field or aVecelement had the wrong type, Rust JSG failed with the inner conversion's error and didn't say where it happened:{ list: 1 }gave "Expected Array but got number". C++ JSG names the field or the index: "Incorrect type for the 'list' field on 'Outer': the provided value is not of type 'Array'." and "Incorrect type for array element 1: ...". I ran the same values through a C++ method and a Rust method with the same signature, and this accounted for about 70 of the 100 message diffs.In this patch, struct fields and
Vecelements convert withtry_from_js. A value that isn't of the expected type gets C++ JSG's message, built by one helper,Error::new_incorrect_type.Dictentries and method arguments now use it too. An error thrown during conversion still passes through unchanged. A struct'sfrom_jsnow goes through itstry_from_js, so a nested struct no longer checks the value's type twice. The README also notes two differences that remain:Stringis a USVString, so a lone surrogate comes back as one U+FFFD. C++ JSG's WTF-8kj::Stringgives three.Vecfollows the new length. C++ JSG reads the length once.