Skip to content

Commit

Permalink
Bug 1076 conversion error flattening (#1216)
Browse files Browse the repository at this point in the history
This is the SDK companion to
stellar/rs-soroban-env#1339 -- it won't work
until that change has landed and its refs have updated to point to it.

There's an explanation of the change over there, but briefly: we were
discarding meaningful errors when passing through the `TryFromVal<ScVal>
for Val` and `TryFromVal<Val> for ScVal` impls in env-common, and now
(or at least if 1339 lands) we're not. Instead of returning
`ConversionError` we'd be returning `Error`.

The SDK happens to _also_ have conversions with `ConversionError`
signatures, and I've opted in this PR to _not_ go a step further and
actually change those to `Error`, instead re-burying the `Error` into
`ConversionError` in the SDK, keeping the SDK APIs as they are. I could
also change them. But I figured that could be left to @leighmcculloch's
choice; he might want to keep the SDK's error repertoire simpler, I'm
not sure.
  • Loading branch information
graydon authored Feb 2, 2024
1 parent 63e865e commit b156ab4
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 32 deletions.
28 changes: 14 additions & 14 deletions Cargo.lock

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

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ soroban-ledger-snapshot = { version = "20.2.0", path = "soroban-ledger-snapshot"
soroban-token-sdk = { version = "20.2.0", path = "soroban-token-sdk" }

[workspace.dependencies.soroban-env-common]
version = "=20.1.0"
version = "=20.1.1"
git = "https://github.com/stellar/rs-soroban-env"
rev = "c1b238b65bfd13666be4ac14e0e390c31b549caf"
rev = "096d4614299ac08c93d255a5482dd079873265dd"

[workspace.dependencies.soroban-env-guest]
version = "=20.1.0"
version = "=20.1.1"
git = "https://github.com/stellar/rs-soroban-env"
rev = "c1b238b65bfd13666be4ac14e0e390c31b549caf"
rev = "096d4614299ac08c93d255a5482dd079873265dd"

[workspace.dependencies.soroban-env-host]
version = "=20.1.0"
version = "=20.1.1"
git = "https://github.com/stellar/rs-soroban-env"
rev = "c1b238b65bfd13666be4ac14e0e390c31b549caf"
rev = "096d4614299ac08c93d255a5482dd079873265dd"

[workspace.dependencies.stellar-strkey]
version = "=0.0.8"
Expand Down
2 changes: 1 addition & 1 deletion soroban-sdk/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl TryFromVal<Env, &Address> for Val {
impl TryFrom<&Address> for ScVal {
type Error = ConversionError;
fn try_from(v: &Address) -> Result<Self, ConversionError> {
ScVal::try_from_val(&v.env, &v.obj.to_val())
Ok(ScVal::try_from_val(&v.env, &v.obj.to_val())?)
}
}

Expand Down
4 changes: 2 additions & 2 deletions soroban-sdk/src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ impl From<&Bytes> for Bytes {
impl TryFrom<&Bytes> for ScVal {
type Error = ConversionError;
fn try_from(v: &Bytes) -> Result<Self, ConversionError> {
ScVal::try_from_val(&v.env, &v.obj.to_val())
Ok(ScVal::try_from_val(&v.env, &v.obj.to_val())?)
}
}

Expand Down Expand Up @@ -894,7 +894,7 @@ impl<const N: usize> From<&BytesN<N>> for Bytes {
impl<const N: usize> TryFrom<&BytesN<N>> for ScVal {
type Error = ConversionError;
fn try_from(v: &BytesN<N>) -> Result<Self, ConversionError> {
ScVal::try_from_val(&v.0.env, &v.0.obj.to_val())
Ok(ScVal::try_from_val(&v.0.env, &v.0.obj.to_val())?)
}
}

Expand Down
2 changes: 1 addition & 1 deletion soroban-sdk/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ where
impl<K, V> TryFrom<&Map<K, V>> for ScVal {
type Error = ConversionError;
fn try_from(v: &Map<K, V>) -> Result<Self, ConversionError> {
ScVal::try_from_val(&v.env, &v.obj.to_val())
Ok(ScVal::try_from_val(&v.env, &v.obj.to_val())?)
}
}

Expand Down
2 changes: 1 addition & 1 deletion soroban-sdk/src/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ macro_rules! impl_num_wrapping_val_type {
if let Ok(ss) = <$small>::try_from(v.val) {
ScVal::try_from(ss)
} else {
ScVal::try_from_val(&v.env, &v.to_val())
Ok(ScVal::try_from_val(&v.env, &v.to_val())?)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion soroban-sdk/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl From<&String> for String {
impl TryFrom<&String> for ScVal {
type Error = ConversionError;
fn try_from(v: &String) -> Result<Self, ConversionError> {
ScVal::try_from_val(&v.env, &v.obj.to_val())
Ok(ScVal::try_from_val(&v.env, &v.obj.to_val())?)
}
}

Expand Down
2 changes: 1 addition & 1 deletion soroban-sdk/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl TryFrom<&Symbol> for ScVal {
Ok(ScVal::try_from(ss)?)
} else {
let e: Env = v.env.clone().try_into()?;
ScVal::try_from_val(&e, &v.to_val())
Ok(ScVal::try_from_val(&e, &v.to_val())?)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions soroban-sdk/src/tests/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ fn default_and_from_snapshot_same_settings() {

let logs1 = env1.logs().all();
let logs2 = env2.logs().all();
assert_eq!(logs1, &["[Diagnostic Event] contract:0000000000000000000000000000000000000000000000000000000000000001, topics:[log], data:\"test\""]);
assert_eq!(logs2, &["[Diagnostic Event] contract:0000000000000000000000000000000000000000000000000000000000000001, topics:[log], data:\"test\""]);
assert_eq!(logs1, &["[Diagnostic Event] contract:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM, topics:[log], data:\"test\""]);
assert_eq!(logs2, &["[Diagnostic Event] contract:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM, topics:[log], data:\"test\""]);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion soroban-sdk/src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ use super::xdr::{ScVal, ScVec, VecM};
impl<T> TryFrom<&Vec<T>> for ScVal {
type Error = ConversionError;
fn try_from(v: &Vec<T>) -> Result<Self, ConversionError> {
ScVal::try_from_val(&v.env, &v.obj.to_val())
Ok(ScVal::try_from_val(&v.env, &v.obj.to_val())?)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@
"symbol": "symbol"
},
"val": {
"string": "aaa\\0"
"string": "aaa"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@
"symbol": "symbol"
},
"val": {
"string": "aaa\\0"
"string": "aaa"
}
}
]
Expand Down

0 comments on commit b156ab4

Please sign in to comment.