Skip to content

Commit

Permalink
Merge pull request #30 from KusionStack/panic-parser-err
Browse files Browse the repository at this point in the history
fix: disable print panic info
  • Loading branch information
Peefy authored May 24, 2022
2 parents f4bf03a + ab973a1 commit a3155a1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions kclvm/runtime/src/_kcl_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub extern "C" fn _kcl_run(
) -> kclvm_size_t {
let ctx = kclvm_context_new();

let prev_hook = std::panic::take_hook();
std::panic::set_hook(Box::new(|info: &std::panic::PanicInfo| {
let ctx = Context::current_context_mut();
ctx.set_panic_info(info);
Expand All @@ -77,6 +78,7 @@ pub extern "C" fn _kcl_run(
result_buffer,
)
});
std::panic::set_hook(prev_hook);
match result {
Ok(n) => {
let json_panic_info = Context::current_context().get_panic_info_json_string();
Expand Down
Binary file modified kclvm/runtime/src/_kclvm.bc
Binary file not shown.
9 changes: 8 additions & 1 deletion kclvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ use kclvm_tools::query::apply_overrides;

#[no_mangle]
pub extern "C" fn kclvm_cli_run(args: *const i8, plugin_agent: *const i8) -> *const i8 {
match std::panic::catch_unwind(|| kclvm_cli_run_unsafe(args, plugin_agent)) {
let prev_hook = std::panic::take_hook();

// disable print panic info
std::panic::set_hook(Box::new(|_info| {}));
let kclvm_cli_run_unsafe_result = std::panic::catch_unwind(|| kclvm_cli_run_unsafe(args, plugin_agent));
std::panic::set_hook(prev_hook);

match kclvm_cli_run_unsafe_result {
Ok(result) => match result {
Ok(result) => {
let c_string =
Expand Down

0 comments on commit a3155a1

Please sign in to comment.