0xSpaceShard / starknet-devnet-rs

A local testnet for Starknet... in Rust
https://0xspaceshard.github.io/starknet-devnet-rs/
MIT License
107 stars 62 forks source link

cairo lang errs #435

Closed lordshashank closed 6 months ago

lordshashank commented 6 months ago

Usage related changes

improves error handling

Development related changes

Resolves https://github.com/0xSpaceShard/starknet-devnet-rs/issues/198

Checklist:

lordshashank commented 6 months ago

@marioiordanov is this what you meant (I took sierra errors from cairo_lang_starknet_classes, as cairo_lang_starknet had just abi errors in it) ? I have also not removed the "reason" property, let me know if you want it removed.

marioiordanov commented 6 months ago

@lordshashank just make it as TransactionExecutionError(#[from] TransactionExecutionError)

lordshashank commented 6 months ago

@marioiordanov did that as following

    #[error(transparent)]
    SierraCompilationError(#[from] StarknetSierraCompilationError),

Now, I tried to use ? to auto parse error here but its not working, should I use StarknetSierraCompilationError variants here?

marioiordanov commented 6 months ago

@lordshashank take a look at other error variants that have the same structure

lordshashank commented 6 months ago

@marioiordanov , I have looked into the other variants, thing is StarknetSierraCompilationError has many variants here, Would downcasting work here so as to get the variant automatically like this

                let casm_json = usc::compile_contract(serde_json::to_value(sierra_contract_class).map_err(
                    |err| Error::JsonError(JsonError::Custom { msg: err.to_string() }),
                )?).map_err(|err| {
                    let err_str = err.to_string();
                    if let Some(sierra_error) = err.downcast::<StarknetSierraCompilationError>().ok() {
                        Error::SierraCompilationError(sierra_error)
                    } else {
                        Error::UnexpectedError(err_str)
                    }
                })?;

or should I use some specific variant only?

marioiordanov commented 6 months ago

@lordshashank sorry about misleading you, just add a String to the SierraCompilationError variant and then create the variant like this: Error::SierraCompilationError(err_str)

lordshashank commented 6 months ago

@marioiordanov I don't understand, do you want StarknetSierraCompilationError Error derivation for SierraCompilationError to be removed here and just make variant from string message, if thats the case, it is already like that in repo's current state, then what changes do we intend to do in the issue?

marioiordanov commented 6 months ago

I just saw that there are two SierraCompilationError variants in different crates. Replace usage of SierraCompilationError variant from starknet_devnet_core::errors::Error with TypesError(starknet_devnet_types::error::Error::SierraCompilationError). Then delete the variant from starknet_devnet_core

lordshashank commented 6 months ago

@marioiordanov did that, let me know if something else is to be done here.

lordshashank commented 6 months ago

@marioiordanov should we change issue description if this is all to be done?

marioiordanov commented 6 months ago

@lordshashank we will just make a comment. Have to run the CI to approve your PR

lordshashank commented 6 months ago

Ok let me know if CI fails.