Repository navigation
Keep the worker_do_not_log marker on a jsg::Error from a KJ exception - #8619
Conversation
C++ marks a KJ exception that is not worth logging, often because it was already logged, with worker_do_not_log, and C++ JSG then throws it to JavaScript as an internal error that it logs only at INFO, without the reference ID (reportInternalException() in jsg/util.c++). Rust JSG lost the marker: From<cxx::KjException> for jsg::Error peeled it off in from_kj_description() and dropped it, and Lock::throw_exception() logged the error again at ERROR, with its ID, through makeInternalError(). jsg::Deserializer's header error, which it logs with LOG_WARNING_PERIODICALLY before throwing, is one such exception. jsg::Error now keeps whether its KJ exception had the marker, found where C++ tunneledErrorType() looks for it, and Lock::throw_exception() and Lock::exception() log such an internal error at INFO without the ID. The isolate_throw_internal_error() and exception_create_internal() shims take an InternalErrorLog that says how to log; the do-not-log error is built with V8 and makeInternalErrorId() rather than C++ JSG, so the shims use C++ JSG no more than before. Other internal errors are logged as before. Keeping the whole kj::Exception and throwing it with C++ JSG's exceptionToJs() was not done: it is C++ JSG that the shims may not use, and it would give JavaScript properties such as retryable and overloaded that Rust JSG's internal error does not have. jsg-test gets fail_with_kj_exception(), a C++ call that fails with a given KJ exception, and capture_kj_logs(), which records what KJ logs, as KJ_EXPECT_LOG observes it in C++ tests. Compatibility: Workers observe no change. JavaScript gets the same "internal error; reference = <id>" Error as before; only what workerd logs for an internal error from a worker_do_not_log exception changes.
guybedford
left a comment
There was a problem hiding this comment.
LGTM. I checked the marker lookup against tunneledErrorType() and it matches, including the expected ...; case. Two nits inline, neither blocking.
…ror-keep-do-not-log
Rename InternalErrorLog::WithId / DoNotLog to Error / Info, since the latter still logs at INFO and the former logs without an ID while execution is terminating. Clarify that exception in the enum's docs and update the Rust and C++ callers and existing assertions. The worker_do_not_log change also changes the termination-path ERROR log's expression label from "kj::heapString(internalMessage.data(), internalMessage.size()) = ..." to "message = ...". KJ_LOG stringifies its argument expression, so this changes Sentry grouping for that path even though the severity and message content stay the same. The original commit's statement that other internal errors are logged as before needs this qualification. Compatibility: no Worker-visible API or behavior changes. Validation: just format on the four changed files; just test --config=bazelflare --test_size_filters= //src/rust/... (181 targets passed; two sanitizer fixtures skipped).
There was a problem hiding this comment.
✅ Approved — The marker is kept and the log severity matches C++ JSG; I found no issues in the code, tests or docs, and both earlier comments have been addressed.
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
Internal error messages stay redacted from JavaScript. The INFO log leaves out the reference ID.
📖 AGENTS.md: ✅ LGTM
The src/rust/AGENTS.md edit is accurate.
📋 Code Quality: ✅ LGTM
Marker lookup, INFO-path logging, reference ID handling and do_not_log initialisation on every Error constructor all look correct. The tests cover both ways the error reaches JavaScript: thrown, and as a value.
⚡ Performance: ✅ LGTM
No performance concerns.
📝 Documentation: ✅ LGTM
The doc comments and the AGENTS.md update match the new Error / Info names.
Reviewed commit: ee65b524
Rust JSG dropped the worker_do_not_log marker when converting KJ
exceptions to jsg::Error. Already-logged failures, such as
deserializer header errors, were logged again at ERROR with a
reference ID.
Preserve the marker and log these internal errors at INFO without the
ID, matching C++ JSG. The shims select the severity with
InternalErrorLog::Error / Info without adding uses of C++ JSG. Tests
cover marker detection, severity, reference IDs and redaction for both
thrown errors and error values.
The termination-path log's expression label also changes from
kj::heapString(internalMessage.data(), internalMessage.size()) to
message. This changes Sentry grouping for that path; severity and
message content stay the same.
Compatibility: no Worker-visible changes. JavaScript still receives an
Error with the message "internal error; reference = ".