Skip to content

Keep &str panic messages in cxx's kj exceptions - #8763

Merged
littledivy merged 1 commit into
mainfrom
littledivy/2026-11-21-rjsg-panic-str-payload
Nov 24, 2026
Merged

littledivy merged 1 commit into
mainfrom
littledivy/2026-11-21-rjsg-panic-str-payload

Conversation

@littledivy

Copy link
Copy Markdown
Member

When a Rust function exposed through cxx panics, panic_result turns the payload into a kj::Exception, but it only read String payloads. A panic!("literal") with no format arguments carries a &'static str, so C++ got panic in <fn> and lost the message.

In this patch panic_result reads both payload types. The new r_panic_literal test in //src/rust/cxx/tests:test fails without the fix.

When a Rust function exposed through cxx panics, panic_result turns the
payload into a kj::Exception, but it only read String payloads. A
`panic!("literal")` with no format arguments carries a &'static str, so
C++ got "panic in <fn>" and lost the message.

In this patch panic_result reads both payload types. The new
r_panic_literal test fails without the fix.
@littledivy
littledivy requested review from a team as code owners November 21, 2026 02:53

@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 — A small, correct fix that keeps &'static str panic messages in the kj exception, covered by a test that fails without it. No issues found.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

📋 Code Quality: ✅ LGTM

panic_result now reads both String and &'static str payloads. The borrow taken by message ends before err is moved in the CanceledException branch, and the CanceledException handling is unchanged. The new r_panic_literal test checks the exact message, so it would fail on the old code.


📝 Documentation: ✅ LGTM

The new comments are accurate and describe the code as it is now.


Reviewed commit: 0653a279

@littledivy
littledivy merged commit 9472364 into main Nov 24, 2026
36 of 38 checks passed
@littledivy
littledivy deleted the littledivy/2026-11-21-rjsg-panic-str-payload branch November 24, 2026 03:04
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