Ray's Knowledge Base
Unlock

rquickjs surfaces a thrown JS Error as "Exception generated by QuickJS"; extract the message with ctx.catch()

PitfallVerified 18 Oct 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

A config function that does throw new Error("boom") reports an error whose text is command keys.prefix.1: Exception generated by QuickJS, losing the "boom" detail the requirement needs.

Cause#

In rquickjs 0.14, the Rust Error returned by call.call() only formats as the generic Exception generated by QuickJS; the actual thrown JS value (an Error object with .message) is left pending on the context. Reporting {error} gives only the generic string.

Fix#

Inside the Ctx::with closure, when the call returns Err, call ctx.catch() to retrieve the thrown value as a rquickjs::Value, then Exception::from_object(value.into_object()?) and .message(). This both clears the pending exception and recovers the real message. Fall back to error.to_string() when the thrown value is not an Error. Do not import rquickjs::Value in a module that already uses serde_json::Value (name collision); use the fully-qualified rquickjs::Value.

Evidence#

In rmaestro, crates/rmaestro-script/src/host.rs run_command/handle_event originally did ctx.catch() only to clear (fn clear), so send_error(format!("command {name}: {error}")) printed Exception generated by QuickJS. A new exception_message(ctx, result) helper that does let caught: rquickjs::Value = ctx.catch(); caught.into_object().and_then(Exception::from_object).and_then(|e| e.message()) produced command keys.prefix.1: boom, matching REQ-qzzn7p. crates/rmaestro-script/src/load.rs already used this idiom for load-time runtime errors.