Repository navigation
Fail a Rust worker interface with the kj::Exception itself - #8728
Conversation
There was a problem hiding this comment.
Superseded by the review of
9bb840ea.
This review, of 3900b4c8
✅ Approved — I found no problems. The clone bridge pairs new with the existing delete drop, and the trait error-type change is converted the same way at every implementation and listener.
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
I found no security concerns. What reaches JavaScript is still only the exception's type and description, and the extra context and traces only show up in server-side logs.
📖 AGENTS.md: ✅ LGTM
Nothing in this pull request makes the existing contributor guidance wrong.
📋 Code Quality: ✅ LGTM
I found no correctness or maintainability problems. KjException::clone() goes through kj::Exception::clone(). The memory it allocates with new is freed by the existing dropInPlace delete. The KjError → KjException conversions at the trait boundaries in kj-hyper, the worker crate and the server services are applied the same way everywhere.
⚡ Performance: ✅ LGTM
The change only affects error paths: at most one exception clone per failure. It adds no cost to successful requests.
📝 Documentation: ✅ LGTM
The new doc comments match the behaviour.
Reviewed commit: 3900b4c8
3900b4c to
9bb840e
Compare
There was a problem hiding this comment.
Superseded by the review of
9ab77185.
This review, of 9bb840ea
✅ Approved — No findings. The clone bridge pairs new with the existing delete drop, and the KjError to KjException conversions are applied the same way at every trait implementation and listener.
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
I found no security concerns. What reaches JavaScript is still only the exception's type and description; the extra context and traces only reach C++ callers and server-side logs.
📖 AGENTS.md: ✅ LGTM
Nothing in this pull request makes the existing contributor guidance out of date.
📋 Code Quality: ✅ LGTM
I found no problems.
- Clone bridge:
cxxbridge1$kjException$clonecreates the copy withnew kj::Exception(err->clone()), and the existingdropInPlacefrees it withdelete, so the two match.test_kj_exception_clonechecks that the copy is a separate allocation and that the type, description, location and details carry over. PromisedInterface::new:IntoKjExceptionis implemented forKjException, forKjErrorand for anystd::error::Error. These impls don't overlap, becauseKjExceptionis not anError.- Trait boundaries: every
KjErroris turned into aKjExceptionat the trait method, with.into()or?. The helper methods behind them (the kj-hyper client and the disk, bucket and cache services) still returnKjError. - Tests: the new C++ test checks all eight events through
CxxWorkerInterface,request()andconnect()included. ThePromisedInterfacetests now check that the context, remote trace and stack trace survive the clone.
⚡ Performance: ✅ LGTM
Only error paths change. The extra work is one kj::Exception::clone() per failed event on PromisedInterface, plus the conversions at the trait boundaries. Successful requests cost nothing extra.
📝 Documentation: ✅ LGTM
The new doc comments match the behaviour.
Reviewed commit: 9bb840ea
worker::Result and kj::http::Service's request() and connect() failed with a KjError, which keeps only an exception's type, description, location and details. A C++ exception that passed through a Rust interface, such as a C++ worker wrapped by CxxWorkerInterface, came back without its context, remote trace and stack trace. Their error is now the KjException, which reaches C++ as the exception it is. Service implementations spell it kj::http::ServiceResult. KjError remains the error of the code around them: an implementation that builds a KjError converts it at the trait method with ?, which gives an error without a location the location of the conversion. kj-hyper's client and the disk, bucket and cache services keep their bodies as KjError methods and convert once. A listener that drives an interface turns a failure back into a KjError to log it, as it did before. PromisedInterface::new() takes a startup future that fails with any error that converts to a KjException, and gives an error without a location the location of the call. A KjException can now be cloned with kj::Exception::clone(), which copies everything the exception holds, its context, remote trace and stack trace included, so a Rust holder of a KjException can hand out copies without converting through KjError.
9bb840e to
9ab7718
Compare
There was a problem hiding this comment.
✅ Approved — No findings. The only change since the approved review is the new C++ test, which correctly checks that the full exception comes back from all eight events.
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. JavaScript still gets only the exception's type and description.
📖 AGENTS.md: ✅ LGTM
Nothing in this pull request makes the existing contributor guidance out of date.
📋 Code Quality: ✅ LGTM
The new test sets up all eight events and its exception checks correctly. startFailure() now adds a context, a remote trace and a stack trace, and expectStartFailure checks for exactly those.
⚡ Performance: ✅ LGTM
Only test code changed since the last review.
📝 Documentation: ✅ LGTM
No documentation issues.
Reviewed commit: 9ab77185
cloudflare#8728 changed worker::Result to carry a KjException, and cloudflare#8727, which merged after it, still returns a KjError from AlarmOwnedElsewhere, so main no longer compiles workerd-server. Convert the error where it is made.
A Rust
worker::Interfaceorkj::http::Servicefails with aKjError, which keeps only an exception's type, description, locationand details. A C++ exception that passes through one, such as from a
C++ worker wrapped by
CxxWorkerInterface, loses its context, remotetrace and stack trace. Rust interfaces should be able to stand in for
C++ ones without that loss, which porting
WorkerInterface::fromException()and similar needs.The first commit lets a
KjExceptionbe cloned withkj::Exception::clone(). The second makesKjExceptionthe error ofworker::Resultand ofService::request()andconnect(), spelledkj::http::ServiceResult. Code that builds aKjErrorconverts it atthe trait method with
?. The kj crate's own wrappers, such asServiceResponse::send(), and the Rust server's listener logging stilluse
KjError; moving those is a separate change.A Worker sees no difference, since JavaScript still gets only the type
and description; C++ callers now get the full exception. A new C++ test
fails all eight events of a wrapped C++ worker with an exception that
carries a context, a remote trace and a stack trace, and checks each
comes back whole. The
PromisedInterfacetests check the same for theclone every later event gets. Both fail when the exception is reduced to
a
KjError. The full test suite passes.