Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ununderstandable return data when panic #1253

Closed
Fransr24 opened this issue Mar 11, 2024 · 5 comments
Closed

Ununderstandable return data when panic #1253

Fransr24 opened this issue Mar 11, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@Fransr24
Copy link

What version are you using?

Soroban 20.3.0

What did you do?

When invoking a contract in a local node using the soroban CLI with a command similar to:
soroban contract invoke --id $ContractId --source alice --network standalone -- $FunctionName
And if the invoked function contains a panic statement for a specific condition, such as:
panic!("cannot swap token to same one")
And you intentionally trigger that condition to observe the error returned from the function, you might expect to receive an error message that explains what occurred during the function invocation.

What did you expect to see?

The expected output should be: "cannot swap token to same one", providing clarity about the issue encountered during the function execution. This information would help in understanding the cause of the error.

What did you see instead?

2024-03-11T13:42:43.457552Z ERROR soroban_cli::log::diagnostic_event: 0: "AAAAAAAAAAAAAAAAAAAAAgAAAAAAAAADAAAADwAAAAdmbl9jYWxsAAAAAA0AAAAgaIrWof44t/3KfQliJyAyzhb1b8psJTyxiadzJA9PcakAAAAPAAAADWVzdGltYXRlX3N3YXAAAAAAAAAQAAAAAQAAAAMAAAADAAAAAAAAAAMAAAAAAAAACQAAAAAAAAAAAAAAAAAAAGE="
2024-03-11T13:42:43.457589Z ERROR soroban_cli::log::diagnostic_event: 1: "AAAAAAAAAAAAAAABaIrWof44t/3KfQliJyAyzhb1b8psJTyxiadzJA9PcakAAAACAAAAAAAAAAIAAAAPAAAABWVycm9yAAAAAAAAAgAAAAEAAAAGAAAAEAAAAAEAAAACAAAADgAAACdWTSBjYWxsIHRyYXBwZWQ6IFVucmVhY2hhYmxlQ29kZVJlYWNoZWQAAAAADwAAAA1lc3RpbWF0ZV9zd2FwAAAA"
error: transaction simulation failed: host invocation failed

Caused by:
    HostError: Error(WasmVm, InvalidAction)
    
    Event log (newest first):
       0: [Diagnostic Event] contract:CBUIVVVB7Y4LP7OKPUEWEJZAGLHBN5LPZJWCKPFRRGTXGJAPJ5Y2TZYG, topics:[error, Error(WasmVm, InvalidAction)], data:["VM call trapped: UnreachableCodeReached", estimate_swap]
       1: [Diagnostic Event] topics:[fn_call, Bytes(688ad6a1fe38b7fdca7d0962272032ce16f56fca6c253cb189a773240f4f71a9), estimate_swap], data:[0, 0, 97]
    
    Backtrace (newest first):
       0: soroban_env_host::budget::Budget::with_shadow_mode
       1: soroban_env_host::budget::Budget::with_shadow_mode
       2: soroban_env_host::host::error::<impl soroban_env_host::host::Host>::error
       3: soroban_env_host::vm::Vm::invoke_function_raw
       4: soroban_env_host::host::frame::<impl soroban_env_host::host::Host>::with_frame
       5: soroban_env_host::host::frame::<impl soroban_env_host::host::Host>::call_n_internal
       6: soroban_env_host::host::frame::<impl soroban_env_host::host::Host>::invoke_function
       7: soroban_simulation::simulate_invoke_hf_op
       8: preflight::preflight_invoke_hf_op::{{closure}}
       9: core::ops::function::FnOnce::call_once{{vtable.shim}}
      10: preflight::catch_preflight_panic
      11: _cgo_e635fd1dbb9c_Cfunc_preflight_invoke_hf_op
                 at /tmp/go-build/cgo-gcc-prolog:106:11
      12: runtime.asmcgocall
                 at ./runtime/asm_amd64.s:872

With this output, I'm not able to know what is the problem that triggered the panic

@Fransr24 Fransr24 added the bug Something isn't working label Mar 11, 2024
@github-project-automation github-project-automation bot moved this to Backlog in DevX Mar 11, 2024
@willemneal
Copy link
Member

What contract is this? Stellar Asset Contract? My guess is that the issue here is that the code has unreachable!() or another panic and not using using an Error, which does provide more context.

@Fransr24
Copy link
Author

This issue occurs in every contract that utilizes the panic! macro. Even in a basic "hello world" contract, invoking panic! will produce the same output.

@willemneal
Copy link
Member

Well from a CLI perspective there isn't much to be done about the use of panic!. Currently rs-soroban-sdk/rs-soroban-env, don't capture the string used in a panic. This is why panic_with_error with added:

https://github.com/stellar/rs-soroban-sdk/blob/89efc3c211d41f1ab143bed0a09cd6af353bb098/soroban-sdk/src/lib.rs#L649-L661

Either way it is always better to use a Result as then it is clear to the caller that there is an error and if there is an error it is formatted correctly.

@willemneal
Copy link
Member

Digging deeper, this is the reason, the panic handler uses unreachable and ignores anything past to it.

https://github.com/stellar/rs-soroban-sdk/blob/89efc3c211d41f1ab143bed0a09cd6af353bb098/soroban-sdk/src/lib.rs#L53-L55

@leighmcculloch
Copy link
Member

leighmcculloch commented Mar 12, 2024

This is a limitation of panic! and not something the CLI could change. The rs-soroban-sdk and rs-soroban-env could be changed to capture and log the string, but it doesn't do that today.

Recommend looking at the errors tutorial which shows how to create an error type and return errors from the contract, or panic with errors:

@leighmcculloch leighmcculloch closed this as not planned Won't fix, can't repro, duplicate, stale Mar 12, 2024
@github-project-automation github-project-automation bot moved this from Backlog to Done in DevX Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

3 participants