diff --git a/examples/stable_memory/package-lock.json b/examples/stable_memory/package-lock.json index 0f4771fa14..ea31dafc33 100644 --- a/examples/stable_memory/package-lock.json +++ b/examples/stable_memory/package-lock.json @@ -13,7 +13,7 @@ "jest": "^29.7.0", "ts-jest": "^29.1.5", "ts-node": "10.7.0", - "typescript": "4.6.3" + "typescript": "^5.2.2" } }, "node_modules/@adraffy/ens-normalize": { @@ -2042,18 +2042,6 @@ } } }, - "node_modules/azle/node_modules/typescript": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", - "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=14.17" - } - }, "node_modules/babel-jest": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-29.7.0.tgz", @@ -5417,15 +5405,15 @@ "integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==" }, "node_modules/typescript": { - "version": "4.6.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.3.tgz", - "integrity": "sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw==", + "version": "5.5.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.3.tgz", + "integrity": "sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ==", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" }, "engines": { - "node": ">=4.2.0" + "node": ">=14.17" } }, "node_modules/universalify": { @@ -7049,11 +7037,6 @@ "make-error": "^1.1.1", "yn": "3.1.1" } - }, - "typescript": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", - "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==" } } }, @@ -9594,9 +9577,9 @@ "integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==" }, "typescript": { - "version": "4.6.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.3.tgz", - "integrity": "sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw==" + "version": "5.5.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.3.tgz", + "integrity": "sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ==" }, "universalify": { "version": "2.0.0", diff --git a/examples/stable_memory/test/tests.ts b/examples/stable_memory/test/tests.ts index d66a4432c2..48c1639877 100644 --- a/examples/stable_memory/test/tests.ts +++ b/examples/stable_memory/test/tests.ts @@ -154,7 +154,6 @@ export function getTests(stableMemoryCanister: ActorSubclass<_SERVICE>): Test { const expectedErrorMessage = new RegExp( `Call was rejected:\\s*Request ID: [a-f0-9]{64}\\s*Reject code: 5\\s*Reject text: ${rejectionMessage.source}` ); - ('OutOfMemoryCool'); await expect(stableMemoryCanister.stableGrow(1)).rejects.toThrow( expectedErrorMessage ); diff --git a/src/compiler/compile_rust_code.ts b/src/compiler/compile_rust_code.ts index 4cba7fd08e..8a01fc4673 100644 --- a/src/compiler/compile_rust_code.ts +++ b/src/compiler/compile_rust_code.ts @@ -14,15 +14,6 @@ export async function compileRustCode( compilerInfo: CompilerInfo, canisterConfig: CanisterConfig ): Promise { - if (nativeCompilation === true) { - compileRustCodeNatively( - `.azle/${canisterName}/${canisterName}.wasm`, - canisterName, - stdio - ); - return; - } - if (process.env.AZLE_GENERATE_STATIC_CANISTER_TEMPLATE === 'true') { compileRustCodeNatively( STATIC_CANISTER_TEMPLATE_PATH, diff --git a/src/compiler/index.ts b/src/compiler/index.ts index ee0afc0590..ee086f04db 100644 --- a/src/compiler/index.ts +++ b/src/compiler/index.ts @@ -29,6 +29,7 @@ async function azle(): Promise { return; } + // TODO can we just get names once? const { stdioType, wasmedgeQuickJsPath, @@ -72,6 +73,7 @@ async function azle(): Promise { ) ); + // TODO this might should only happen if we compile await prepareRustStagingArea( canisterConfig, canisterPath, @@ -105,6 +107,7 @@ async function azle(): Promise { canisterMethods.post_upgrade?.index ?? -1 ); + // TODO probably not required anymore // This is for the dfx.json candid property await writeFile(candidPath, candid); diff --git a/src/compiler/rust/canister_methods/src/lib.rs b/src/compiler/rust/canister_methods/src/lib.rs index 2f713341d8..2d289f41f7 100644 --- a/src/compiler/rust/canister_methods/src/lib.rs +++ b/src/compiler/rust/canister_methods/src/lib.rs @@ -65,6 +65,28 @@ pub fn canister_methods(_: TokenStream) -> TokenStream { #[no_mangle] #[allow(unused)] pub fn init(function_index: i32, pass_arg_data: i32) { + std::panic::set_hook(Box::new(|panic_info| { + let msg = if let Some(s) = panic_info.payload().downcast_ref::<&str>() { + *s + } else if let Some(s) = panic_info.payload().downcast_ref::() { + s.as_str() + } else { + "Unknown panic message" + }; + + let location = if let Some(location) = panic_info.location() { + format!(" at {}:{}", location.file(), location.line()) + } else { + " (unknown location)".to_string() + }; + + let message = &format!("Panic occurred: {}{}", msg, location); + + ic_cdk::println!("{}", message); + + ic_cdk::trap(message); + })); + let wasm_data = get_wasm_data(); let env_vars: Vec<(&str, &str)> = wasm_data.env_vars.iter().map(|(key, value)| (key.as_str(), value.as_str())).collect(); @@ -94,6 +116,28 @@ pub fn canister_methods(_: TokenStream) -> TokenStream { #[no_mangle] #[allow(unused)] pub fn post_upgrade(function_index: i32, pass_arg_data: i32) { + std::panic::set_hook(Box::new(|panic_info| { + let msg = if let Some(s) = panic_info.payload().downcast_ref::<&str>() { + *s + } else if let Some(s) = panic_info.payload().downcast_ref::() { + s.as_str() + } else { + "Unknown panic message" + }; + + let location = if let Some(location) = panic_info.location() { + format!(" at {}:{}", location.file(), location.line()) + } else { + " (unknown location)".to_string() + }; + + let message = &format!("Panic occurred: {}{}", msg, location); + + ic_cdk::println!("{}", message); + + ic_cdk::trap(message); + })); + let wasm_data = get_wasm_data(); let env_vars: Vec<(&str, &str)> = wasm_data.env_vars.iter().map(|(key, value)| (key.as_str(), value.as_str())).collect(); diff --git a/static_canister_template.wasm b/static_canister_template.wasm index bdc1559cb6..bab46fb8cc 100644 Binary files a/static_canister_template.wasm and b/static_canister_template.wasm differ diff --git a/tests/end_to_end/candid_rpc/class_syntax/stable_memory/package-lock.json b/tests/end_to_end/candid_rpc/class_syntax/stable_memory/package-lock.json index 780027c7bf..e841bf3891 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/stable_memory/package-lock.json +++ b/tests/end_to_end/candid_rpc/class_syntax/stable_memory/package-lock.json @@ -13,7 +13,7 @@ "stable_memory_end_to_end_test_functional_syntax": "file:../../../../../examples/stable_memory", "ts-jest": "^29.1.5", "ts-node": "10.7.0", - "typescript": "4.6.3" + "typescript": "^5.2.2" } }, "../../../../../examples/stable_memory": { @@ -27,7 +27,7 @@ "jest": "^29.7.0", "ts-jest": "^29.1.5", "ts-node": "10.7.0", - "typescript": "4.6.3" + "typescript": "^5.2.2" } }, "node_modules/@adraffy/ens-normalize": { @@ -2056,18 +2056,6 @@ } } }, - "node_modules/azle/node_modules/typescript": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", - "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=14.17" - } - }, "node_modules/babel-jest": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-29.7.0.tgz", @@ -5435,15 +5423,15 @@ "integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==" }, "node_modules/typescript": { - "version": "4.6.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.3.tgz", - "integrity": "sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw==", + "version": "5.5.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.3.tgz", + "integrity": "sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ==", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" }, "engines": { - "node": ">=4.2.0" + "node": ">=14.17" } }, "node_modules/universalify": { @@ -7067,11 +7055,6 @@ "make-error": "^1.1.1", "yn": "3.1.1" } - }, - "typescript": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", - "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==" } } }, @@ -9426,7 +9409,7 @@ "jest": "^29.7.0", "ts-jest": "^29.1.5", "ts-node": "10.7.0", - "typescript": "4.6.3" + "typescript": "^5.2.2" } }, "stack-utils": { @@ -9623,9 +9606,9 @@ "integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==" }, "typescript": { - "version": "4.6.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.3.tgz", - "integrity": "sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw==" + "version": "5.5.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.3.tgz", + "integrity": "sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ==" }, "universalify": { "version": "2.0.0",