From 63940d3327bbe5777181fe3c195c7660120151f3 Mon Sep 17 00:00:00 2001 From: Arvid Norlander Date: Wed, 17 Jul 2024 10:23:00 +0200 Subject: [PATCH 1/3] rune: Do not trace return value (causes panic on Result:Err) (cherry picked from commit 26cce04c57fcb1cd4d5abce16b9d74a53e185ba8) --- crates/rune/src/runtime/vm.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/rune/src/runtime/vm.rs b/crates/rune/src/runtime/vm.rs index a11fdebf5..ef3bc1e1e 100644 --- a/crates/rune/src/runtime/vm.rs +++ b/crates/rune/src/runtime/vm.rs @@ -2058,7 +2058,7 @@ impl Vm { } #[inline] - #[tracing::instrument(skip(self))] + #[tracing::instrument(skip(self, return_value))] fn op_return_internal( &mut self, return_value: Value, From 952b5fb726377f5afbf61fd415f20e92b8687c85 Mon Sep 17 00:00:00 2001 From: Arvid Norlander Date: Wed, 17 Jul 2024 10:54:51 +0200 Subject: [PATCH 2/3] rune: Backport changes to Value::string_debug_with This ensures that we don't get an error on formatting a value without a debug protocol. (fixes #747) --- crates/rune/src/runtime/value.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/rune/src/runtime/value.rs b/crates/rune/src/runtime/value.rs index 461369c19..2227cbcf9 100644 --- a/crates/rune/src/runtime/value.rs +++ b/crates/rune/src/runtime/value.rs @@ -495,11 +495,16 @@ impl Value { vm_write!(f, "{:?}", value); } value => { + // reborrow f to avoid moving it let result = - vm_try!(caller.call_protocol_fn(Protocol::STRING_DEBUG, value.clone(), (f,),)); + caller.call_protocol_fn(Protocol::STRING_DEBUG, self.clone(), (&mut *f,)); - vm_try!(<()>::from_value(result)); - return VmResult::Ok(()); + if let VmResult::Ok(result) = result { + vm_try!(<()>::from_value(result)); + } else { + let type_info = vm_try!(value.type_info()); + vm_write!(f, "<{} object at {:p}>", type_info, value); + } } }; From 60f2f541d5f7a6d6431c4ca80ef8cc02bf1ac234 Mon Sep 17 00:00:00 2001 From: Arvid Norlander Date: Wed, 17 Jul 2024 12:28:40 +0200 Subject: [PATCH 3/3] rune: Never error in Value debug formatting Instead attempt to print *something* --- crates/rune/src/runtime/value.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/rune/src/runtime/value.rs b/crates/rune/src/runtime/value.rs index 2227cbcf9..558bff3a1 100644 --- a/crates/rune/src/runtime/value.rs +++ b/crates/rune/src/runtime/value.rs @@ -2035,7 +2035,15 @@ impl fmt::Debug for Value { let mut o = Formatter::new(); if value.string_debug(&mut o).is_err() { - return Err(fmt::Error); + match value.type_info() { + VmResult::Ok(type_info) => { + write!(f, "<{} object at {:p}>", type_info, value)?; + } + VmResult::Err(e) => { + write!(f, "", value, e)?; + } + } + return Ok(()); } f.write_str(o.as_str())?;