Skip to content

Commit

Permalink
improve: use a struct variant to clarify the error argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelmmiguel committed Jul 5, 2023
1 parent 3cf16ae commit c51311f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
16 changes: 12 additions & 4 deletions kits/javascript/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,13 @@ pub fn load_bindings_into_global(
}
}
})
.map_err(|_| RuntimeError::InvalidBinding("send_http_request".to_string()))?,
.map_err(|_| RuntimeError::InvalidBinding {
invalid_export: "send_http_request".to_string(),
})?,
)
.map_err(|_| RuntimeError::InvalidBinding("send_http_request".to_string()))?;
.map_err(|_| RuntimeError::InvalidBinding {
invalid_export: "send_http_request".to_string(),
})?;

global
.set_property(
Expand All @@ -122,9 +126,13 @@ pub fn load_bindings_into_global(

Ok(JSValue::Null)
})
.map_err(|_| RuntimeError::InvalidBinding("console_log".to_string()))?,
.map_err(|_| RuntimeError::InvalidBinding {
invalid_export: "console_log".to_string(),
})?,
)
.map_err(|_| RuntimeError::InvalidBinding("console_log".to_string()))?;
.map_err(|_| RuntimeError::InvalidBinding {
invalid_export: "console_log".to_string(),
})?;

Ok(())
}
2 changes: 1 addition & 1 deletion kits/javascript/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

/// List of runtime errors
pub enum RuntimeError {
InvalidBinding(String),
InvalidBinding { invalid_export: String },
}
4 changes: 2 additions & 2 deletions kits/javascript/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ fn main() {
Ok(_) => {}
Err(e) => match e {
// In the future we may have more errors.
error::RuntimeError::InvalidBinding(name) => {
eprintln!("There was an error adding the '{name}' binding");
error::RuntimeError::InvalidBinding { invalid_export } => {
eprintln!("There was an error adding the '{invalid_export}' binding");
}
},
}
Expand Down
Binary file modified kits/javascript/wasm-workers-quick-js-engine.wasm
Binary file not shown.

0 comments on commit c51311f

Please sign in to comment.