-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
some initial error structure is in place
- Loading branch information
Showing
15 changed files
with
246 additions
and
205 deletions.
There are no files selected for viewing
Binary file not shown.
44 changes: 44 additions & 0 deletions
44
...build/stable/commands/compile/wasm_binary/rust/stable_canister_template/src/azle_error.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#[derive(Debug)] | ||
pub enum AzleError { | ||
Init(Box<dyn std::error::Error>), | ||
PostUpgrade(Box<dyn std::error::Error>), | ||
MethodExecution(Box<dyn std::error::Error>), | ||
QuickJSContextNotInitialized, | ||
QuickJSCallbackExecutionFailed(Box<dyn std::error::Error>), | ||
WasmDataVecToString(Box<dyn std::error::Error>), | ||
WasmDataStringToStruct(Box<dyn std::error::Error>), | ||
} | ||
|
||
impl std::fmt::Display for AzleError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
AzleError::QuickJSContextNotInitialized => { | ||
write!(f, "QuickJS context not initialized") | ||
} | ||
AzleError::QuickJSCallbackExecutionFailed(error) => { | ||
write!(f, "QuickJS callback execution failed: {}", error) | ||
} | ||
AzleError::MethodExecution(error) => { | ||
write!(f, "Azle MethodExecutionError: {}", error) | ||
} | ||
AzleError::Init(error) => write!(f, "Azle InitError: {}", error), | ||
AzleError::PostUpgrade(error) => write!(f, "Azle PostUpgradeError: {}", error), | ||
AzleError::WasmDataVecToString(error) => { | ||
write!( | ||
f, | ||
"WasmData conversion failed while converting Vec<u8> to String: {}", | ||
error | ||
) | ||
} | ||
AzleError::WasmDataStringToStruct(error) => { | ||
write!( | ||
f, | ||
"WasmData conversion failed while converting String to WasmData Struct: {}", | ||
error | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl std::error::Error for AzleError {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 12 additions & 9 deletions
21
...table/commands/compile/wasm_binary/rust/stable_canister_template/src/execute_method_js.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,27 @@ | ||
use crate::quickjs_with_ctx; | ||
use std::error::Error; | ||
|
||
#[no_mangle] | ||
#[allow(unused)] | ||
pub extern "C" fn execute_method_js(function_index: i32, pass_arg_data: i32) { | ||
let function_name = &function_index.to_string(); | ||
let pass_arg_data = if pass_arg_data == 1 { true } else { false }; | ||
let function_name = function_index.to_string(); | ||
let pass_arg_data = pass_arg_data == 1; | ||
|
||
quickjs_with_ctx(|ctx| { | ||
let callbacks: rquickjs::Object = ctx.clone().globals().get("_azleCallbacks").unwrap(); | ||
if let Err(error) = quickjs_with_ctx(|ctx| -> Result<(), Box<dyn Error>> { | ||
let callbacks: rquickjs::Object = ctx.clone().globals().get("_azleCallbacks")?; | ||
|
||
let method_callback: rquickjs::Function = callbacks.get(function_name).unwrap(); | ||
let method_callback: rquickjs::Function = callbacks.get(&function_name)?; | ||
|
||
let candid_args = if pass_arg_data { | ||
ic_cdk::api::call::arg_data_raw() | ||
} else { | ||
vec![] | ||
}; | ||
|
||
method_callback | ||
.call::<_, rquickjs::Undefined>((candid_args,)) | ||
.unwrap(); | ||
}); | ||
method_callback.call::<_, rquickjs::Undefined>((candid_args,))?; | ||
|
||
Ok(()) | ||
}) { | ||
ic_cdk::trap(&format!("Azle MethodExecutionError: {}", error)); | ||
} | ||
} |
3 changes: 1 addition & 2 deletions
3
...table/commands/compile/wasm_binary/rust/stable_canister_template/src/ic/accept_message.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
use rquickjs::{Ctx, Function}; | ||
|
||
pub fn get_function(context: Ctx) -> Function { | ||
pub fn get_function(context: Ctx) -> Result<Function, rquickjs::Error> { | ||
Function::new(context, || { | ||
ic_cdk::api::call::accept_message(); | ||
}) | ||
.unwrap() | ||
} |
3 changes: 1 addition & 2 deletions
3
.../stable/commands/compile/wasm_binary/rust/stable_canister_template/src/ic/arg_data_raw.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
use rquickjs::{Ctx, Function, TypedArray}; | ||
|
||
pub fn get_function(context: Ctx) -> Function { | ||
pub fn get_function(context: Ctx) -> Result<Function, rquickjs::Error> { | ||
Function::new(context.clone(), move || { | ||
TypedArray::<u8>::new(context.clone(), ic_cdk::api::call::arg_data_raw()) | ||
}) | ||
.unwrap() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
src/build/stable/commands/compile/wasm_binary/rust/stable_canister_template/src/ic/caller.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
use rquickjs::{Ctx, Function, TypedArray}; | ||
use rquickjs::{Ctx, Function, Result, TypedArray}; | ||
|
||
pub fn get_function(context: Ctx) -> Function { | ||
pub fn get_function(context: Ctx) -> Result<Function> { | ||
Function::new(context.clone(), move || { | ||
TypedArray::<u8>::new(context.clone(), ic_cdk::api::caller().as_slice()) | ||
}) | ||
.unwrap() | ||
} |
Oops, something went wrong.