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

(minimal) Add EnvBase::Error, remove CheckedEnv, make Env methods return Error #638

Merged
merged 1 commit into from
Jan 23, 2023

Conversation

graydon
Copy link
Contributor

@graydon graydon commented Jan 23, 2023

This is a "minimal" version of #633 that does not touch the TryFromVal trait, just moves CheckedEnv's error functionality into Env by defining Env::Error and making every method return Result<T, Env::Error>.

The main differences are:

  • This version deletes less code, since every TryFromVal still has to define its own Error type.
  • This version loses a bit more information when there's a HostError downgraded to a ConversionError in such a TryFromVal.
  • This version doesn't need Env::escalate_status_to_error or MapErrToEnv, because it does those downgrades / information losses.
  • This version doesn't imply as much change to the SDK.

The last point is evident in the corresponding SDK change: stellar/rs-soroban-sdk#837

@graydon graydon requested review from sisuresh and a team as code owners January 23, 2023 01:12
@graydon graydon changed the title Add EnvBase::Error, remove CheckedEnv, make Env methods return Error (minimal) Add EnvBase::Error, remove CheckedEnv, make Env methods return Error Jan 23, 2023
@graydon graydon merged commit 96ea6dc into main Jan 23, 2023
@graydon graydon deleted the env-err-minimal branch January 23, 2023 23:14
graydon added a commit to stellar/rs-soroban-sdk that referenced this pull request Jan 23, 2023
This is a "minimal" version of
#833, accompanying /
adapting to stellar/rs-soroban-env#638.

If this minimal approach is preferred, this PR and
stellar/rs-soroban-env#638 should be merged
together. Otherwise the more-invasive pair #833 and
stellar/rs-soroban-env#633 should be merged
together.

This one does much less rearranging and makes no difference to the
emitted code at all. It just pushes around where the non-infallible
`Env::Error` cases get escalated: formerly it happened in `impl Env for
CheckedEnv`, now there's a new internal SDK function
`internal::reject_err` that does the work. Infallible errors also need
to be explicitly unwrapped in a bunch of places but this is just a
type-level thing, operationally it's a no-op.

(I should also note: I could do an "even more minimal" version of this
where `soroban_sdk::env::Env` _does not implement_
`soroban_env_common:env::Env`, in which case the "error rejections"
could be buried in the macro-generated code in the SDK and we could
remove all the `.unwrap_infallible` calls in the SDK bodies. I don't
know how important it is for the SDK's Env to implement the common Env.)
@graydon graydon mentioned this pull request Jan 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants