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

All: error handling #415

Open
gangov opened this issue Jan 9, 2025 · 0 comments
Open

All: error handling #415

gangov opened this issue Jan 9, 2025 · 0 comments
Assignees

Comments

@gangov
Copy link
Collaborator

gangov commented Jan 9, 2025

take this sample contract:

#![no_std]
use soroban_sdk::{contract, contracterror, contractimpl, log, Env};

#[contracterror]
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
#[repr(u32)]
pub enum Error {
    Bazz = 1,
}

#[contract]
pub struct ErrorContracts;

#[contractimpl]
impl ErrorContracts {
    pub fn error_enum(env: Env) -> Result<u32, Error> {
        log!(&env, "Error from an enum");
        return Err(Error::Bazz);
    }

    pub fn panic(env: Env) -> Result<u32, Error> {
        panic!("Error from a panic")
    }

    pub fn expect(env: Env) -> Result<u32, Error> {
        let _ = None::<i32>.expect("Error from expect");

        Ok(5u32)
    }
}

currently the error messages that we get from the 3 different calls are as follows:

  • error_enum:
2025-01-09T10:39:40.284153Z ERROR soroban_cli::assembled: 0: "AAAAAAAAAAAAAAAAAAAAAgAAAAAAAAADAAAADwAAAAdmbl9jYWxsAAAAAA0AAAAgWXg0OM8MI6zLkjlxSGWoCYOv5CZngttZM
ZeU7dq6nx8AAAAPAAAACmVycm9yX2VudW0AAAAAAAE="
2025-01-09T10:39:40.284225Z ERROR soroban_cli::assembled: 1: "AAAAAAAAAAAAAAABWXg0OM8MI6zLkjlxSGWoCYOv5CZngttZMZeU7dq6nx8AAAACAAAAAAAAAAIAAAAPAAAABWVycm9yAAAAA
AAAAgAAAAAAAAABAAAADgAAADZlc2NhbGF0aW5nIE9rKFNjRXJyb3JUeXBlOjpDb250cmFjdCkgZnJhbWUtZXhpdCB0byBFcnIAAA=="
❌ error: transaction simulation failed: HostError: Error(Contract, #1)
Event log (newest first):
   0: [Diagnostic Event] contract:CBMXQNBYZ4GCHLGLSI4XCSDFVAEYHL7EEZTYFW2ZGGLZJ3O2XKPR6GR3, topics:[error, Error(Contract, #1)], data:"escalating Ok(ScErrorType::Contract) frame-exit to Err"
   1: [Diagnostic Event] topics:[fn_call, CBMXQNBYZ4GCHLGLSI4XCSDFVAEYHL7EEZTYFW2ZGGLZJ3O2XKPR6GR3, error_enum], data:Void
  • panic:
2025-01-09T10:40:50.592672Z ERROR soroban_cli::assembled: 0: "AAAAAAAAAAAAAAAAAAAAAgAAAAAAAAADAAAADwAAAAdmbl9jYWxsAAAAAA0AAAAgWXg0OM8MI6zLkjlxSGWoCYOv5CZngttZM
ZeU7dq6nx8AAAAPAAAABXBhbmljAAAAAAAAAQ=="
2025-01-09T10:40:50.592757Z ERROR soroban_cli::assembled: 1: "AAAAAAAAAAAAAAABWXg0OM8MI6zLkjlxSGWoCYOv5CZngttZMZeU7dq6nx8AAAACAAAAAAAAAAIAAAAPAAAABWVycm9yAAAAA
AAAAgAAAAEAAAAGAAAAEAAAAAEAAAACAAAADgAAACdWTSBjYWxsIHRyYXBwZWQ6IFVucmVhY2hhYmxlQ29kZVJlYWNoZWQAAAAADwAAAAVwYW5pYwAAAA=="
❌ error: transaction simulation failed: HostError: Error(WasmVm, InvalidAction)
Event log (newest first):
   0: [Diagnostic Event] contract:CBMXQNBYZ4GCHLGLSI4XCSDFVAEYHL7EEZTYFW2ZGGLZJ3O2XKPR6GR3, topics:[error, Error(WasmVm, InvalidAction)], data:["VM call trapped: UnreachableCodeReached", panic]
   1: [Diagnostic Event] topics:[fn_call, CBMXQNBYZ4GCHLGLSI4XCSDFVAEYHL7EEZTYFW2ZGGLZJ3O2XKPR6GR3, panic], data:Void
  • expect:
2025-01-09T10:43:57.766134Z ERROR soroban_cli::assembled: 0: "AAAAAAAAAAAAAAAAAAAAAgAAAAAAAAADAAAADwAAAAdmbl9jYWxsAAAAAA0AAAAgWXg0OM8MI6zLkjlxSGWoCYOv5CZngttZM
ZeU7dq6nx8AAAAPAAAABmV4cGVjdAAAAAAAAQ=="
2025-01-09T10:43:57.766214Z ERROR soroban_cli::assembled: 1: "AAAAAAAAAAAAAAABWXg0OM8MI6zLkjlxSGWoCYOv5CZngttZMZeU7dq6nx8AAAACAAAAAAAAAAIAAAAPAAAABWVycm9yAAAAA
AAAAgAAAAEAAAAGAAAAEAAAAAEAAAACAAAADgAAACdWTSBjYWxsIHRyYXBwZWQ6IFVucmVhY2hhYmxlQ29kZVJlYWNoZWQAAAAADwAAAAZleHBlY3QAAA=="
❌ error: transaction simulation failed: HostError: Error(WasmVm, InvalidAction)
Event log (newest first):
   0: [Diagnostic Event] contract:CBMXQNBYZ4GCHLGLSI4XCSDFVAEYHL7EEZTYFW2ZGGLZJ3O2XKPR6GR3, topics:[error, Error(WasmVm, InvalidAction)], data:["VM call trapped: UnreachableCodeReached", expect]
   1: [Diagnostic Event] topics:[fn_call, CBMXQNBYZ4GCHLGLSI4XCSDFVAEYHL7EEZTYFW2ZGGLZJ3O2XKPR6GR3, expect], data:Void

We should sweep through our codebase and make sure we are using Error enums, instead of panic or expecting

@gangov gangov self-assigned this Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant