Skip to content

Fix xdr_to_json panic for ScType::Val with non-Void values#2472

Open
gabrielrondon wants to merge 1 commit intostellar:mainfrom
gabrielrondon:fix/2469-val-type-panic
Open

Fix xdr_to_json panic for ScType::Val with non-Void values#2472
gabrielrondon wants to merge 1 commit intostellar:mainfrom
gabrielrondon:fix/2469-val-type-panic

Conversation

@gabrielrondon
Copy link
Copy Markdown

What

Handle ScType::Val in xdr_to_json() by delegating to to_json() for all ScVal variants, preventing a panic when the contract spec uses the generic Val return type.

Why

When a contract function returns ScType::Val and the runtime value is anything other than Void (e.g. Bytes, U64, Address), the current code falls through to todo!() and panics. The transaction succeeds on-chain but the CLI crashes during output formatting.

The to_json() function already handles all ScVal variants without needing type information, so it is the correct fallback for the catch-all Val type.

Close #2469

Known limitations

N/A

Copilot AI review requested due to automatic review settings April 8, 2026 09:35
@github-project-automation github-project-automation bot moved this to Backlog (Not Ready) in DevX Apr 8, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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::Val in the xdr_to_json() function by delegating to to_json() for all non-Void values
  • This prevents panic when contract functions use the generic Val return type with any concrete runtime value

self.sc_object_to_json(val, type_)?
}

(val, ScType::Val) => to_json(val)?,
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
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
@gabrielrondon gabrielrondon force-pushed the fix/2469-val-type-panic branch from 580f610 to 7c9e4fa Compare April 12, 2026 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog (Not Ready)

Development

Successfully merging this pull request may close these issues.

CLI panics when formatting output after successful contract invocation when return type is BytesN<32>

2 participants