Repository navigation
Make Rust JSG Nullable<T> follow dont_substitute_null_on_type_error - #8646
Conversation
For a Worker without `dont_substitute_null_on_type_error` (dated before 2022-06-01), C++ JSG converts a value that `T` does not take to `null` for a `kj::Maybe<T>` (value.h, `MaybeWrapper::tryUnwrap`), and only with the flag is it a TypeError. Rust's `Nullable<T>` always threw. Nothing in Rust uses it yet, but a C++ API with a `kj::Maybe` parameter ported to Rust would start throwing for those Workers. In this patch `Nullable<T>` reads the flag when `T` does not take a value: without it the result is `Null`, and with it the conversion throws `T`'s error as before. `NullOrUndefined<T>` goes through `Nullable<T>` for anything but `undefined`, as C++ `jsg::Optional<kj::Maybe<T>>` does. Only the top-level type counts, so an element of the wrong type in a `Nullable<Vec<T>>` is still an error. The flag is read only on a mismatch. The new tests follow "maybes - don't substitute null" in value-test.c++, for `Nullable` of a non-coercible string, of a union, and in a sequence, with and without the flag. The tests that expect the TypeError now set the flag. Refs #8057
There was a problem hiding this comment.
Superseded by the review of
277e10a6.
This review, of d91e6709
✅ Approved — No issues found. The Rust conversion now matches C++ kj::Maybe handling under dont_substitute_null_on_type_error, and tests cover the case with and without the flag.
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.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
No issues found.
⚡ Performance: ✅ LGTM
No issues found. The feature flag is read only when T does not take the value.
📝 Documentation: ✅ LGTM
No issues found.
Reviewed commit: d91e6709
There was a problem hiding this comment.
Superseded by the review of
8bba5b78.
This review, of 277e10a6
✅ Approved — No issues found. The Rust conversion now matches C++ kj::Maybe handling under dont_substitute_null_on_type_error, and tests cover the case with and without the flag.
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.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
No issues found.
⚡ Performance: ✅ LGTM
No issues found. The feature flag is read only when T does not take the value.
📝 Documentation: ✅ LGTM
No issues found.
Reviewed commit: 277e10a6 — same changes as d91e6709, so this is that commit's review (no new review was run; line numbers are as of d91e6709)
There was a problem hiding this comment.
Superseded by the review of
45e5c645.
This review, of 8bba5b78
✅ Approved — No issues found. The Rust conversion now matches C++ kj::Maybe handling under dont_substitute_null_on_type_error, and tests cover the case with and without the flag.
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.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
No issues found.
⚡ Performance: ✅ LGTM
No issues found. The feature flag is read only when T does not take the value.
📝 Documentation: ✅ LGTM
No issues found.
Reviewed commit: 8bba5b78 — same changes as d91e6709, so this is that commit's review (no new review was run; line numbers are as of d91e6709)
There was a problem hiding this comment.
✅ Approved — No issues found. The Rust Nullable<T> conversion now follows the C++ kj::Maybe behaviour under dont_substitute_null_on_type_error, and tests cover it with and without the flag.
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 security concerns. The change only affects how values convert, and it follows the existing C++ compatibility behaviour.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
The changes to Nullable<T> and NullOrUndefined<T> in src/rust/jsg/wrappable.rs match the C++ kj::Maybe behaviour under dont_substitute_null_on_type_error. Without the flag a value of the wrong type becomes Null. With it, the conversion throws T's own error. Tests cover the top-level mismatch, a value inside a union, an element of a sequence, and an element mismatch nested inside a Nullable<Vec<T>>, which stays an error.
⚡ Performance: ✅ LGTM
The flag is read only when T does not take the value, so a successful conversion costs nothing extra.
📝 Documentation: ✅ LGTM
The README now describes how a type mismatch converts with and without the flag, and the section on union conversion links to it.
Reviewed commit: 45e5c645
For a Worker without
dont_substitute_null_on_type_error(dated before 2022-06-01), C++ JSG converts a value thatTdoes not take tonullfor akj::Maybe<T>(MaybeWrapper::tryUnwrapin value.h). Only with the flag is it a TypeError. Rust'sNullable<T>always threw. Nothing in Rust uses it yet, but a C++ API with akj::Maybeparameter ported to Rust would start throwing for those Workers.In this patch
Nullable<T>reads the flag whenTdoes not take a value. Without the flag the result isNull. With it, the conversion throwsT's error as before.NullOrUndefined<T>goes throughNullable<T>for anything butundefined, as C++jsg::Optional<kj::Maybe<T>>does. Only the top-level type counts, so an element of the wrong type in aNullable<Vec<T>>is still an error. The flag is read only on a mismatch.The new tests follow "maybes - don't substitute null" in value-test.c++, for
Nullableof a non-coercible string, of a union, and in a sequence, with and without the flag. The tests that expect the TypeError now set the flag.Refs #8057