Fix xdr_to_json panic for ScType::Val with non-Void values#2472
Fix xdr_to_json panic for ScType::Val with non-Void values#2472gabrielrondon wants to merge 1 commit intostellar:mainfrom
Conversation
When a contract spec declares a return type as Val (the generic catch-all type), any concrete runtime value other than Void falls through to the todo!() panic in xdr_to_json. This causes the CLI to crash on output formatting even though the transaction succeeded. Delegate ScType::Val to to_json() which already handles all ScVal variants without needing type information. Close stellar#2469
There was a problem hiding this comment.
Pull request overview
This PR fixes a panic in the xdr_to_json() function that occurred when a contract function returned ScType::Val (a generic catch-all type) with actual values like Bytes, U64, or Address. The fix adds a single match arm that delegates to the to_json() function, which already handles all ScVal variants appropriately. This resolves issue #2469 where the CLI would crash during output formatting despite the transaction succeeding on-chain.
Changes:
- Added handling for
ScType::Valin thexdr_to_json()function by delegating toto_json()for all non-Void values - This prevents panic when contract functions use the generic
Valreturn type with any concrete runtime value
| self.sc_object_to_json(val, type_)? | ||
| } | ||
|
|
||
| (val, ScType::Val) => to_json(val)?, |
There was a problem hiding this comment.
This PR fixes a panic when handling ScType::Val with non-Void values, but does not include tests for this new behavior. While the fix correctly delegates to the existing to_json() function which is well-tested, it would be beneficial to add a test case for xdr_to_json() with ScType::Val to prevent regressions. This is especially important since the test suite includes tests for related functions like to_json() and the soroban-test integration tests likely test contract return values.
What
Handle
ScType::Valinxdr_to_json()by delegating toto_json()for allScValvariants, preventing a panic when the contract spec uses the genericValreturn type.Why
When a contract function returns
ScType::Valand the runtime value is anything other thanVoid(e.g.Bytes,U64,Address), the current code falls through totodo!()and panics. The transaction succeeds on-chain but the CLI crashes during output formatting.The
to_json()function already handles allScValvariants without needing type information, so it is the correct fallback for the catch-allValtype.Close #2469
Known limitations
N/A