Skip to content

Commit

Permalink
uplink: add ContractError::DoesNotExist variant
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo Leegwater Simões committed Aug 21, 2024
1 parent 6ce487f commit decf50b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions piecrust-uplink/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `ContractError::DoesNotExist` variant

## [0.16.0] - 2024-08-01

### Added
Expand Down
7 changes: 7 additions & 0 deletions piecrust-uplink/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use core::str;
pub enum ContractError {
Panic(String),
OutOfGas,
DoesNotExist,
Unknown,
}

Expand Down Expand Up @@ -57,6 +58,7 @@ impl ContractError {
match code {
-1 => Self::Panic(get_msg(slice)),
-2 => Self::OutOfGas,
-3 => Self::DoesNotExist,
i32::MIN => Self::Unknown,
_ => unreachable!("The host must guarantee that the code is valid"),
}
Expand All @@ -81,6 +83,7 @@ impl ContractError {
-1
}
Self::OutOfGas => -2,
Self::DoesNotExist => -3,
Self::Unknown => i32::MIN,
}
}
Expand All @@ -91,6 +94,7 @@ impl From<ContractError> for i32 {
match err {
ContractError::Panic(_) => -1,
ContractError::OutOfGas => -2,
ContractError::DoesNotExist => -3,
ContractError::Unknown => i32::MIN,
}
}
Expand All @@ -101,6 +105,9 @@ impl Display for ContractError {
match self {
ContractError::Panic(msg) => write!(f, "Panic: {msg}"),
ContractError::OutOfGas => write!(f, "OutOfGas"),
ContractError::DoesNotExist => {
write!(f, "Contract does not exist")
}
ContractError::Unknown => write!(f, "Unknown"),
}
}
Expand Down

0 comments on commit decf50b

Please sign in to comment.