- Notifications
You must be signed in to change notification settings - Fork1.4k
Printing Traceback#4395
-
When using RustPython for embedded scripting purposes, I want to be able to print out the traceback if the input fails. Currently I am using this function: use rustpython::vm;pubfnrun_py(code:&str,filename:&str){match vm::Interpreter::with_init(Default::default(), |vm|{ vm.add_frozen(rustpython_pylib::frozen_stdlib())}).enter(|vm|{let scope = vm.new_scope_with_builtins();let code_obj = vm.compile(code, vm::compiler::Mode::Exec,String::from(filename)).map_err(|err| vm.new_syntax_error(&err))?;return vm.run_code_obj(code_obj, scope);}){Ok(_) =>{}Err(e) =>{println!("{:?}", e.traceback().unwrap());// !!!HERE!!!}};} to call an arbitrary Python string within Rust. Example usage: run_py("print('hi')","main.py"); How can I print the traceback when the program fails? There is no apparent way to turn a traceback to a rust string. |
BetaWas this translation helpful?Give feedback.
All reactions
Figured it out! I iterated overe.args().to_vec() and called.str().unwrap().to_string() on all of them to see all the traceback messages.
Replies: 1 comment
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Figured it out! I iterated over |
BetaWas this translation helpful?Give feedback.
All reactions
This discussion was converted from issue #4393 on January 01, 2023 08:43.