chainerror/searchindex.json

1 line
478 KiB
JSON
Raw Normal View History

{"doc_urls":["index.html#chainerror","index.html#example","index.html#features","tutorial1.html#simple-string-errors","tutorial2.html#simple-chained-string-errors","tutorial2.html#what-did-we-do-here","tutorial3.html#mapping-errors","tutorial4.html#saving-coding-chars","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","end.html#the-end"],"index":{"documentStore":{"docInfo":{"0":{"body":55,"breadcrumbs":1,"title":1},"1":{"body":170,"breadcrumbs":1,"title":1},"10":{"body":1382,"breadcrumbs":3,"title":3},"11":{"body":1349,"breadcrumbs":3,"title":3},"12":{"body":1363,"breadcrumbs":3,"title":3},"13":{"body":1417,"breadcrumbs":2,"title":2},"14":{"body":1423,"breadcrumbs":2,"title":2},"15":{"body":18,"breadcrumbs":1,"title":1},"2":{"body":20,"breadcrumbs":1,"title":1},"3":{"body":94,"breadcrumbs":3,"title":3},"4":{"body":1320,"breadcrumbs":4,"title":4},"5":{"body":44,"breadcrumbs":1,"title":1},"6":{"body":1338,"breadcrumbs":2,"title":2},"7":{"body":1324,"breadcrumbs":3,"title":3},"8":{"body":1337,"breadcrumbs":2,"title":2},"9":{"body":1347,"breadcrumbs":2,"title":2}},"docs":{"0":{"body":"chainerror provides an error backtrace like failure without doing a real backtrace, so even after you strip your binaries, you still have the error backtrace. chainerror has no dependencies! chainerror uses .source() of std::error::Error along with line()! and file()! 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 ChainError<T> struct, chainerror comes with some useful helper macros to save a lot of typing. Debug information is worth it! Now continue reading the Tutorial","breadcrumbs":"chainerror","id":"0","title":"chainerror"},"1":{"body":"Output: $ cargo run -q --example example\nMain Error Report: func1 error calling func2 Error reported by Func2Error: func2 error: calling func3 The root cause was: std::io::Error: Kind( NotFound\n) Debug Error:\nexamples/example.rs:45: func1 error calling func2\nCaused by:\nexamples/example.rs:20: Func2Error(func2 error: calling func3)\nCaused by:\nexamples/example.rs:13: Error reading 'foo.txt'\nCaused by:\nKind(NotFound) use chainerror::*;\nuse std::error::Error;\nuse std::io;\nuse std::result::Result; fn do_some_io() -> Result<(), Box<Error>> { Err(io::Error::from(io::ErrorKind::NotFound))?; Ok(())\n} fn func3() -> Result<(), Box<Error>> { let filename = \"foo.txt\"; do_some_io().map_err(mstrerr!(\"Error reading '{}'\", filename))?; Ok(())\n} derive_str_cherr!(Func2Error); fn func2() -> ChainResult<(), Func2Error> { func3().map_err(mstrerr!(Func2Error, \"func2 error: calling func3\"))?; Ok(())\n} enum Func1Error { Func2, IO(String),\n} impl ::std::fmt::Display for Func1Error { fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { match self { Func1Error::Func2 => write!(f, \"func1 error calling func2\"), Func1Error::IO(filename) => write!(f, \"Error reading '{}'\", filename), } }\n} impl ::std::fmt::Debug for Func1Error { fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { write!(f, \"{}\", self) }\n} fn func1() -> ChainResult<(), Func1Error> { func2().map_err(|e| cherr!(e, Func1Error::Func2))?; let filename = String::from(\"bar.txt\"); do_some_io().map_err(|e| cherr!(e, Func1Error::IO(filename)))?; Ok(())\n} fn main() { if let Err(e) = func1() { match e.kind() { Func1Error::Func2 => eprintln!(\"Main Error Report: func1 error calling func2\"), Func1Error::IO(filename) => { eprintln!(\"Main Error Report: func1 error reading '{}'\", filename) } } if let Some(e) = e.find_chain_cause::<Func2Error>() { eprintln!(\"\\nError reported by Func2Error: {}\", e) } if let Some(e) = e.root_cause() { let ioerror = e.downcast_ref::<io::Error>().unwrap(); eprintln!(\"\\nThe root cause was: std::io::Error: {:#?}\", ioerror); } eprintln!(\"\\nDebug Error: