chainerror/searchindex.js

1 line
674 KiB
JavaScript
Raw Normal View History

Object.assign(window.search, {"doc_urls":["index.html#chainerror","index.html#multiple-output-formats","index.html#tutorial","index.html#license","index.html#contribution","tutorial1.html#simple-string-errors","tutorial2.html#simple-chained-string-errors","tutorial2.html#what-did-we-do-here","tutorial3.html#mapping-errors","tutorial4.html#more-information","tutorial5.html#the-source-of-errors","tutorial6.html#downcast-the-errors","tutorial7.html#the-root-cause-of-all-errors","tutorial8.html#finding-an-error-cause","tutorial9.html#selective-error-handling","tutorial10.html#errorkind-to-the-rescue","tutorial11.html#debug-for-the-errorkind","tutorial12.html#deref-for-the-errorkind","tutorial13.html#writing-a-library","tutorial14.html#going-back-to-std","end.html#the-end"],"index":{"documentStore":{"docInfo":{"0":{"body":196,"breadcrumbs":2,"title":1},"1":{"body":95,"breadcrumbs":4,"title":3},"10":{"body":1403,"breadcrumbs":4,"title":2},"11":{"body":1417,"breadcrumbs":4,"title":2},"12":{"body":1452,"breadcrumbs":6,"title":3},"13":{"body":1415,"breadcrumbs":6,"title":3},"14":{"body":1429,"breadcrumbs":6,"title":3},"15":{"body":1469,"breadcrumbs":4,"title":2},"16":{"body":1482,"breadcrumbs":4,"title":2},"17":{"body":1464,"breadcrumbs":4,"title":2},"18":{"body":1488,"breadcrumbs":4,"title":2},"19":{"body":350,"breadcrumbs":6,"title":3},"2":{"body":2,"breadcrumbs":2,"title":1},"20":{"body":18,"breadcrumbs":2,"title":1},"3":{"body":16,"breadcrumbs":2,"title":1},"4":{"body":21,"breadcrumbs":2,"title":1},"5":{"body":106,"breadcrumbs":6,"title":3},"6":{"body":1383,"breadcrumbs":8,"title":4},"7":{"body":40,"breadcrumbs":5,"title":1},"8":{"body":1403,"breadcrumbs":4,"title":2},"9":{"body":1375,"breadcrumbs":4,"title":2}},"docs":{"0":{"body":"Crate Rust Documentation Coverage Status Maintenance chainerror provides an error backtrace without doing a real backtrace, so even after you strip your binaries, you still have the error backtrace. Having nested function returning errors, the output doesn't tell where the error originates from. use std::path::PathBuf; type BoxedError = Box<dyn std::error::Error + Send + Sync>;\nfn read_config_file(path: PathBuf) -> Result<(), BoxedError> { // do stuff, return other errors let _buf = std::fs::read_to_string(&path)?; // do stuff, return other errors Ok(())\n} fn process_config_file() -> Result<(), BoxedError> { // do stuff, return other errors let _buf = read_config_file(\"foo.txt\".into())?; // do stuff, return other errors Ok(())\n} fn main() { if let Err(e) = process_config_file() { eprintln!(\"Error:\\n{:?}\", e); }\n} This gives the output: Error:\nOs { code: 2, kind: NotFound, message: \"No such file or directory\" } and you have no idea where it comes from. With chainerror, you can supply a context and get a nice error backtrace: use chainerror::Context as _;\nuse std::path::PathBuf; type BoxedError = Box<dyn std::error::Error + Send + Sync>;\nfn read_config_file(path: PathBuf) -> Result<(), BoxedError> { // do stuff, return other errors let _buf = std::fs::read_to_string(&path).context(format!(\"Reading file: {:?}\", &path))?; // do stuff, return other errors Ok(())\n} fn process_config_file() -> Result<(), BoxedError> { // do stuff, return other errors let _buf = read_config_file(\"foo.txt\".into()).context(\"read the config file\")?; // do stuff, return other errors Ok(())\n} fn main() { if let Err(e) = process_config_file() { eprintln!(\"Error:\\n{:?}\", e); }\n} with the output: Error:\nexamples/simple.rs:14:51: read the config file\nCaused by:\nexamples/simple.rs:7:47: Reading file: \"foo.txt\"\nCaused by:\nOs { code: 2, kind: NotFound, message: \"No such file or directory\" } chainerror uses .source() of std::error::Error along with #[track_caller] and Location to provide a nice debug error backtrace. It encapsulates all types, which have Display + Debug and can store the error cause internally. Along with the Error<T> struct, chainerror comes with some useful helper macros to save a lot of typing. chainerror has no dependencies! Debug information is worth it!","breadcrumbs":"chainer