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

Err reform #940

Merged
merged 1 commit into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 7 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ soroban-token-sdk = { version = "0.8.4", path = "soroban-token-sdk" }
[workspace.dependencies.soroban-env-common]
version = "0.0.16"
git = "https://github.com/stellar/rs-soroban-env"
rev = "0c0cae6fa22b751e7fd95d7ce7556ac6d7b7010e"
rev = "3762edfe52aafc6c0935619211d76d2d05fe87e6"

[workspace.dependencies.soroban-env-guest]
version = "0.0.16"
git = "https://github.com/stellar/rs-soroban-env"
rev = "0c0cae6fa22b751e7fd95d7ce7556ac6d7b7010e"
rev = "3762edfe52aafc6c0935619211d76d2d05fe87e6"

[workspace.dependencies.soroban-env-host]
version = "0.0.16"
git = "https://github.com/stellar/rs-soroban-env"
rev = "0c0cae6fa22b751e7fd95d7ce7556ac6d7b7010e"
rev = "3762edfe52aafc6c0935619211d76d2d05fe87e6"

[workspace.dependencies.stellar-strkey]
version = "0.0.7"
Expand All @@ -55,7 +55,7 @@ git = "https://github.com/stellar/rs-stellar-strkey"
[workspace.dependencies.stellar-xdr]
version = "0.0.16"
git = "https://github.com/stellar/rs-stellar-xdr"
rev = "53e1a9cf2335aff29305c72deb6f075e78915dad"
rev = "b283ec0bcb791610013107b9eab7d7ff07a65db1"
default-features = false

#[patch."https://github.com/stellar/rs-soroban-env"]
Expand Down
3 changes: 2 additions & 1 deletion soroban-ledger-snapshot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ edition = "2021"
rust-version = "1.69"

[dependencies]
soroban-env-host = { workspace = true, features = ["serde"] }
soroban-env-host = { workspace = true }
soroban-env-common = {workspace = true, features = ["serde"]}
serde = { version = "1.0.0", features = ["derive"] }
serde_json = "1.0.0"
thiserror = "1.0"
Expand Down
9 changes: 6 additions & 3 deletions soroban-ledger-snapshot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ use std::{
rc::Rc,
};

use soroban_env_common::xdr::{ScErrorCode, ScErrorType};
use soroban_env_host::{
storage::SnapshotSource,
xdr::{LedgerEntry, LedgerKey, ScHostStorageErrorCode, ScStatus},
xdr::{LedgerEntry, LedgerKey, ScError},
Host, HostError, LedgerInfo,
};

Expand Down Expand Up @@ -165,9 +166,11 @@ impl SnapshotSource for &LedgerSnapshot {
fn get(&self, key: &Rc<LedgerKey>) -> Result<Rc<LedgerEntry>, HostError> {
match self.ledger_entries.iter().find(|(k, _)| &**k == &**key) {
Some((_, v)) => Ok(Rc::new(*v.clone())),
None => {
Err(ScStatus::HostStorageError(ScHostStorageErrorCode::AccessToUnknownEntry).into())
None => Err(ScError {
type_: ScErrorType::Storage,
code: ScErrorCode::MissingValue,
}
.into()),
}
}
fn has(&self, key: &Rc<LedgerKey>) -> Result<bool, HostError> {
Expand Down
16 changes: 8 additions & 8 deletions soroban-sdk-macros/src/derive_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub fn derive_type_enum(
impl #path::TryFromVal<#path::Env, #path::RawVal> for #enum_ident {
type Error = #path::ConversionError;
#[inline(always)]
fn try_from_val(env: &#path::Env, val: &#path::RawVal) -> Result<Self, Self::Error> {
fn try_from_val(env: &#path::Env, val: &#path::RawVal) -> Result<Self, #path::ConversionError> {
use #path::{EnvBase,TryIntoVal,TryFromVal};
const CASES: &'static [&'static str] = &[#(#case_name_str_lits),*];
let vec: #path::Vec<#path::RawVal> = val.try_into_val(env)?;
Expand All @@ -183,7 +183,7 @@ pub fn derive_type_enum(
impl #path::TryFromVal<#path::Env, #enum_ident> for #path::RawVal {
type Error = #path::ConversionError;
#[inline(always)]
fn try_from_val(env: &#path::Env, val: &#enum_ident) -> Result<Self, Self::Error> {
fn try_from_val(env: &#path::Env, val: &#enum_ident) -> Result<Self, #path::ConversionError> {
use #path::{TryIntoVal,TryFromVal};
match val {
#(#try_intos,)*
Expand All @@ -195,7 +195,7 @@ pub fn derive_type_enum(
impl #path::TryFromVal<#path::Env, #path::xdr::ScVec> for #enum_ident {
type Error = #path::xdr::Error;
#[inline(always)]
fn try_from_val(env: &#path::Env, val: &#path::xdr::ScVec) -> Result<Self, Self::Error> {
fn try_from_val(env: &#path::Env, val: &#path::xdr::ScVec) -> Result<Self, #path::xdr::Error> {
use #path::xdr::Validate;
use #path::TryIntoVal;

Expand All @@ -215,7 +215,7 @@ pub fn derive_type_enum(
impl #path::TryFromVal<#path::Env, #path::xdr::ScVal> for #enum_ident {
type Error = #path::xdr::Error;
#[inline(always)]
fn try_from_val(env: &#path::Env, val: &#path::xdr::ScVal) -> Result<Self, Self::Error> {
fn try_from_val(env: &#path::Env, val: &#path::xdr::ScVal) -> Result<Self, #path::xdr::Error> {
if let #path::xdr::ScVal::Vec(Some(vec)) = val {
<_ as #path::TryFromVal<_, _>>::try_from_val(env, vec)
} else {
Expand All @@ -228,7 +228,7 @@ pub fn derive_type_enum(
impl TryFrom<&#enum_ident> for #path::xdr::ScVec {
type Error = #path::xdr::Error;
#[inline(always)]
fn try_from(val: &#enum_ident) -> Result<Self, Self::Error> {
fn try_from(val: &#enum_ident) -> Result<Self, #path::xdr::Error> {
extern crate alloc;
Ok(match val {
#(#into_xdrs,)*
Expand All @@ -240,7 +240,7 @@ pub fn derive_type_enum(
impl TryFrom<#enum_ident> for #path::xdr::ScVec {
type Error = #path::xdr::Error;
#[inline(always)]
fn try_from(val: #enum_ident) -> Result<Self, Self::Error> {
fn try_from(val: #enum_ident) -> Result<Self, #path::xdr::Error> {
(&val).try_into()
}
}
Expand All @@ -249,7 +249,7 @@ pub fn derive_type_enum(
impl TryFrom<&#enum_ident> for #path::xdr::ScVal {
type Error = #path::xdr::Error;
#[inline(always)]
fn try_from(val: &#enum_ident) -> Result<Self, Self::Error> {
fn try_from(val: &#enum_ident) -> Result<Self, #path::xdr::Error> {
Ok(#path::xdr::ScVal::Vec(Some(val.try_into()?)))
}
}
Expand All @@ -258,7 +258,7 @@ pub fn derive_type_enum(
impl TryFrom<#enum_ident> for #path::xdr::ScVal {
type Error = #path::xdr::Error;
#[inline(always)]
fn try_from(val: #enum_ident) -> Result<Self, Self::Error> {
fn try_from(val: #enum_ident) -> Result<Self, #path::xdr::Error> {
(&val).try_into()
}
}
Expand Down
10 changes: 5 additions & 5 deletions soroban-sdk-macros/src/derive_enum_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub fn derive_type_enum_int(
impl #path::TryFromVal<#path::Env, #path::RawVal> for #enum_ident {
type Error = #path::ConversionError;
#[inline(always)]
fn try_from_val(env: &#path::Env, val: &#path::RawVal) -> Result<Self, Self::Error> {
fn try_from_val(env: &#path::Env, val: &#path::RawVal) -> Result<Self, #path::ConversionError> {
use #path::TryIntoVal;
let discriminant: u32 = val.try_into_val(env)?;
Ok(match discriminant {
Expand All @@ -109,7 +109,7 @@ pub fn derive_type_enum_int(
impl #path::TryFromVal<#path::Env, #enum_ident> for #path::RawVal {
type Error = #path::ConversionError;
#[inline(always)]
fn try_from_val(env: &#path::Env, val: &#enum_ident) -> Result<Self, Self::Error> {
fn try_from_val(env: &#path::Env, val: &#enum_ident) -> Result<Self, #path::ConversionError> {
Ok(match val {
#(#try_intos,)*
})
Expand All @@ -120,7 +120,7 @@ pub fn derive_type_enum_int(
impl #path::TryFromVal<#path::Env, #path::xdr::ScVal> for #enum_ident {
type Error = #path::xdr::Error;
#[inline(always)]
fn try_from_val(env: &#path::Env, val: &#path::xdr::ScVal) -> Result<Self, Self::Error> {
fn try_from_val(env: &#path::Env, val: &#path::xdr::ScVal) -> Result<Self, #path::xdr::Error> {
if let #path::xdr::ScVal::U32(discriminant) = val {
Ok(match *discriminant {
#(#try_froms,)*
Expand All @@ -136,7 +136,7 @@ pub fn derive_type_enum_int(
impl TryInto<#path::xdr::ScVal> for &#enum_ident {
type Error = #path::xdr::Error;
#[inline(always)]
fn try_into(self) -> Result<#path::xdr::ScVal, Self::Error> {
fn try_into(self) -> Result<#path::xdr::ScVal, #path::xdr::Error> {
Ok((*self as u32).into())
}
}
Expand All @@ -145,7 +145,7 @@ pub fn derive_type_enum_int(
impl TryInto<#path::xdr::ScVal> for #enum_ident {
type Error = #path::xdr::Error;
#[inline(always)]
fn try_into(self) -> Result<#path::xdr::ScVal, Self::Error> {
fn try_into(self) -> Result<#path::xdr::ScVal, #path::xdr::Error> {
Ok((self as u32).into())
}
}
Expand Down
44 changes: 22 additions & 22 deletions soroban-sdk-macros/src/derive_error_enum_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn derive_type_error_enum_int(
};
let try_from = quote! { #discriminant => Self::#ident };
let into =
quote! { #enum_ident::#ident => #path::Status::from_contract_error(#discriminant) };
quote! { #enum_ident::#ident => #path::Error::from_contract_error(#discriminant) };
(spec_case, try_from, into)
})
.multiunzip();
Expand Down Expand Up @@ -90,61 +90,61 @@ pub fn derive_type_error_enum_int(
quote! {
#spec_gen

impl TryFrom<#path::Status> for #enum_ident {
type Error = #path::Status;
impl TryFrom<#path::Error> for #enum_ident {
type Error = #path::Error;
#[inline(always)]
fn try_from(status: #path::Status) -> Result<Self, Self::Error> {
if status.is_type(#path::xdr::ScStatusType::ContractError) {
let discriminant = status.get_code();
fn try_from(error: #path::Error) -> Result<Self, #path::Error> {
if error.is_type(#path::xdr::ScErrorType::Contract) {
let discriminant = error.get_code();
Ok(match discriminant {
#(#try_froms,)*
_ => return Err(status),
_ => return Err(error),
})
} else {
Err(status)
Err(error)
}
}
}

impl TryFrom<&#path::Status> for #enum_ident {
type Error = #path::Status;
impl TryFrom<&#path::Error> for #enum_ident {
type Error = #path::Error;
#[inline(always)]
fn try_from(status: &#path::Status) -> Result<Self, Self::Error> {
<_ as TryFrom<#path::Status>>::try_from(*status)
fn try_from(error: &#path::Error) -> Result<Self, #path::Error> {
<_ as TryFrom<#path::Error>>::try_from(*error)
}
}

impl From<#enum_ident> for #path::Status {
impl From<#enum_ident> for #path::Error {
#[inline(always)]
fn from(val: #enum_ident) -> #path::Status {
fn from(val: #enum_ident) -> #path::Error {
match val {
#(#intos,)*
}
}
}

impl From<&#enum_ident> for #path::Status {
impl From<&#enum_ident> for #path::Error {
#[inline(always)]
fn from(val: &#enum_ident) -> #path::Status {
fn from(val: &#enum_ident) -> #path::Error {
<_ as From<#enum_ident>>::from(*val)
}
}

impl #path::TryFromVal<#path::Env, #path::RawVal> for #enum_ident {
type Error = #path::ConversionError;
#[inline(always)]
fn try_from_val(env: &#path::Env, val: &#path::RawVal) -> Result<Self, Self::Error> {
fn try_from_val(env: &#path::Env, val: &#path::RawVal) -> Result<Self, #path::ConversionError> {
use #path::TryIntoVal;
let status: #path::Status = val.try_into_val(env)?;
status.try_into().map_err(|_| #path::ConversionError)
let error: #path::Error = val.try_into_val(env)?;
error.try_into().map_err(|_| #path::ConversionError)
}
}
impl #path::TryFromVal<#path::Env, #enum_ident> for #path::RawVal {
type Error = #path::ConversionError;
#[inline(always)]
fn try_from_val(env: &#path::Env, val: &#enum_ident) -> Result<Self, Self::Error> {
let status: #path::Status = val.into();
Ok(status.into())
fn try_from_val(env: &#path::Env, val: &#enum_ident) -> Result<Self, #path::ConversionError> {
let error: #path::Error = val.into();
Ok(error.into())
}
}
}
Expand Down
Loading