Skip to content

Commit

Permalink
Implement From<interpreter::Error> for wasefire_error::Error (#579)
Browse files Browse the repository at this point in the history
Part of #577 because starting an applet (dynamically) should not crash
the platform in case of errors but instead propagate the error to the
host.

---------

Co-authored-by: Julien Cretin <github-review@ia0.eu>
  • Loading branch information
ia0 and ia0-review authored Aug 9, 2024
1 parent 1c73bfd commit d57d3dd
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 10 deletions.
6 changes: 6 additions & 0 deletions crates/interpreter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.3.1-git

### Minor

- Implement `From<Error>` for `wasefire_error::Error`

## 0.3.0

### Major
Expand Down
10 changes: 9 additions & 1 deletion crates/interpreter/Cargo.lock

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

3 changes: 2 additions & 1 deletion crates/interpreter/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wasefire-interpreter"
version = "0.3.0"
version = "0.3.1-git"
authors = ["Julien Cretin <cretin@google.com>"]
license = "Apache-2.0"
publish = true
Expand All @@ -17,6 +17,7 @@ lru = { version = "0.12.3", default-features = false, optional = true }
num_enum = { version = "0.7.2", default-features = false }
paste = { version = "1.0.15", default-features = false }
portable-atomic = { version = "1.6.0", default-features = false }
wasefire-error = { version = "0.1.2-git", path = "../error" }

[dev-dependencies]
lazy_static = "1.4.0"
Expand Down
14 changes: 14 additions & 0 deletions crates/interpreter/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ pub enum Error {
Trap,
}

pub const TRAP_CODE: u16 = 0xffff;

impl From<Error> for wasefire_error::Error {
fn from(value: Error) -> Self {
use wasefire_error::{Code, Error as WError};
match value {
Error::Invalid => WError::user(Code::InvalidArgument),
Error::NotFound => WError::user(Code::NotFound),
Error::Unsupported(_) => WError::internal(Code::NotImplemented),
Error::Trap => WError::user(TRAP_CODE),
}
}
}

#[cfg(not(feature = "debug"))]
pub type Unsupported = ();

Expand Down
2 changes: 1 addition & 1 deletion crates/interpreter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ mod syntax;
mod toctou;
mod valid;

pub use error::{Error, Unsupported};
pub use error::{Error, Unsupported, TRAP_CODE};
pub use exec::{Call, InstId, RunAnswer, RunResult, Store, StoreId, Val, MEMORY_ALIGN};
pub use module::Module;
pub use syntax::{
Expand Down
3 changes: 2 additions & 1 deletion crates/runner-host/Cargo.lock

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

3 changes: 2 additions & 1 deletion crates/runner-nordic/Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/runner-nordic/src/board/uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ impl Api for Impl {
if EASY_DMA_SIZE < input.len() || !in_ram(input) {
return Err(Error::user(Code::InvalidArgument));
}
with_state(|state| {
with_state::<Result<_, Error>>(|state| {
let Uart { regs, state } = state.uarts.get(uart);
Error::user(Code::InvalidState).check(state.running)?;
regs.txd.ptr.write(|w| unsafe { w.ptr().bits(input.as_ptr() as u32) });
Expand Down
2 changes: 1 addition & 1 deletion crates/scheduler/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,4 @@

## 0.1.0

<!-- Increment to skip CHANGELOG.md test: 3 -->
<!-- Increment to skip CHANGELOG.md test: 4 -->
3 changes: 2 additions & 1 deletion crates/scheduler/Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/scheduler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ wasefire-store = { version = "0.3.0-git", path = "../store", optional = true }
wasefire-sync = { version = "0.1.1", path = "../sync", optional = true }

[dependencies.wasefire-interpreter]
version = "0.3.0"
version = "0.3.1-git"
path = "../interpreter"
features = ["toctou"]
optional = true
Expand Down
10 changes: 9 additions & 1 deletion crates/wasm-bench/Cargo.lock

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

0 comments on commit d57d3dd

Please sign in to comment.