near / near-workspaces-rs

Write tests once, run them both on NEAR TestNet and a controlled NEAR Sandbox local environment via Rust
83 stars 47 forks source link

Not easy to get the exact error message from contract #191

Open joshuajbouw opened 2 years ago

joshuajbouw commented 2 years ago

I've been trying for the last while to get the fail result from the contract from ExecutionFailure. For ExecutionSuccess this is fine because I can return the json, borsh or raw_bytes quite easily. However, this isn't exceptionally straightforward on how to return the value field from ExecutionFailure! This would be an improvement if it is possible to return similar types as it is possible for successes.

ChaoticTempest commented 2 years ago

The value: TxExecutionError field for ExecutionFailure is meant to be hidden as we do not want to expose it as a transient dependency. There's no direct methods to usually interact with it unless you require something from it? It doesn't return bytes, so there's nothing to be operated on it like you'd do with json/borsh in the case of successful execution. It's moreso an opaque error type, and not meant to be directly handled besides just for debugging purposes; in which case you can format! it to get the error message.

ghost commented 11 months ago

@frol Let's close this issue

frol commented 11 months ago

Well, contracts should have a proper standard for error handling that is easy to react from the client side code: https://github.com/near/near-sdk-rs/issues/936. I will keep this issue open and will try to push something from near-sdk-rs side first and then we can resolve this issue here as well. Meanwhile .to_string() is the only way to get the error.