Skip to content

Keep the worker_do_not_log marker on a jsg::Error from a KJ exception - #8619

Merged
bartlomieju merged 3 commits into
mainfrom
biwanczuk/rust-jsg-error-keep-do-not-log
Nov 19, 2026
Merged

bartlomieju merged 3 commits into
mainfrom
biwanczuk/rust-jsg-error-keep-do-not-log

Conversation

@bartlomieju

@bartlomieju bartlomieju commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

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 = ".

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 guybedford left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I checked the marker lookup against tunneledErrorType() and it matches, including the expected ...; case. Two nits inline, neither blocking.

Comment thread src/rust/jsg/ffi.c++ Resolved
Comment thread src/rust/jsg/v8.rs Resolved
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).
@bartlomieju
bartlomieju marked this pull request as ready for review November 19, 2026 12:34
@bartlomieju
bartlomieju requested review from a team as code owners November 19, 2026 12:34

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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

@bartlomieju
bartlomieju merged commit d63dd73 into main Nov 19, 2026
38 of 39 checks passed
@bartlomieju
bartlomieju deleted the biwanczuk/rust-jsg-error-keep-do-not-log branch November 19, 2026 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants