-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make try_ fns return smaller SDK error type (#1175)
### What Make try_ fns return smaller SDK error type instead of the large host error type. ### Why The host error type contains a massive number of possible errors. However, the host obfuscates the error when it is passed to the guest, and so the guest and sdk only ever see the Context/InvalidAction error. It's confusing for developers if we expose the host error type, then don't actually surface most of the errors on it. A developer might think they can distingish between different error states, when in reality they cannot. Close #1136
- Loading branch information
1 parent
8c5eba9
commit 464fb58
Showing
7 changed files
with
444 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use core::convert::Infallible; | ||
|
||
use crate::xdr; | ||
|
||
/// InvokeError captures errors returned from the invocation of another | ||
/// contract. | ||
#[derive(Debug, Copy, Clone, Eq, PartialEq)] | ||
pub enum InvokeError { | ||
/// Abort occurs if the invoke contract panicks with a [`panic!`], or a host | ||
/// function of the environment has a failure, or a runtime error occurs. | ||
Abort, | ||
/// Contract error occurs if the invoked contract function exited returning | ||
/// an error or called [`panic_with_error!`][crate::panic_with_error!] with | ||
/// a [`contracterror`][crate::contracterror]. | ||
/// | ||
/// If the contract defines a [`contracterror`][crate::contracterror] type | ||
/// as part of its interface, this variant of the error will be convertible | ||
/// to that type, but if that conversion failed then this variant of the | ||
/// error would be used to represent the error. | ||
Contract(u32), | ||
} | ||
|
||
impl From<crate::Error> for InvokeError { | ||
fn from(e: crate::Error) -> Self { | ||
if e.is_type(xdr::ScErrorType::Contract) { | ||
InvokeError::Contract(e.get_code()) | ||
} else { | ||
InvokeError::Abort | ||
} | ||
} | ||
} | ||
|
||
impl From<Infallible> for InvokeError { | ||
fn from(_: Infallible) -> Self { | ||
unreachable!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.