{"id":17128024,"url":"https://github.com/novacrazy/trace-error","last_synced_at":"2025-09-15T08:06:18.942Z","repository":{"id":57670459,"uuid":"79119170","full_name":"novacrazy/trace-error","owner":"novacrazy","description":"Extensions to Rust's error system to automatically include backtraces","archived":false,"fork":false,"pushed_at":"2017-04-09T03:35:28.000Z","size":16,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-05T14:01:46.619Z","etag":null,"topics":["backtrace","error-handling","rust","rust-error"],"latest_commit_sha":null,"homepage":"https://docs.rs/trace-error","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/novacrazy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-16T13:08:15.000Z","updated_at":"2024-02-07T21:17:11.000Z","dependencies_parsed_at":"2022-09-26T20:41:05.430Z","dependency_job_id":null,"html_url":"https://github.com/novacrazy/trace-error","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novacrazy%2Ftrace-error","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novacrazy%2Ftrace-error/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novacrazy%2Ftrace-error/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novacrazy%2Ftrace-error/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/novacrazy","download_url":"https://codeload.github.com/novacrazy/trace-error/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240044394,"owners_count":19739183,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backtrace","error-handling","rust","rust-error"],"created_at":"2024-10-14T19:06:03.341Z","updated_at":"2025-02-23T01:30:49.677Z","avatar_url":"https://github.com/novacrazy.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"trace-error\n===========\n\nExtensions to Rust's error system to automatically include backtraces\nto the exact location an error originates.\n\nConsider this a more lightweight and less macro-based alternative to `error_chain` and similar crates. This crate\ndoes not take care of actually defining the errors and their varieties, but only focuses on a thin container\nfor holding the errors and a backtrace to their origin.\n\n`Trace` and `TraceResult` should usually be used in place of `Result` using the macros\n`throw!`, `try_throw!`, and `try_rethrow!`\n\nAlthough the `?` syntax was just introduced, `trace-error` is not yet compatible with it until the `Carrier` trait is stabilized. As a result,\nall instances of `try!` and `?` should be replaced with `try_throw!` if you intend to use this crate to its fullest. However, the `?` operator\ncan be used for `Result\u003c_, Trace\u003cE\u003e\u003e` when the return value is also a `Result` using `Trace\u003cE\u003e`, just because `From` is implemented for types for itself.\n\nAdditionally, if you must use the `Result\u003cT, Trace\u003cE\u003e\u003e` directly instead of immediately returning it, you can use the `trace_error!` macro to create it with the desired error value.\n\nIf the `Trace` being returned in a result does **NOT** contain the same error type, but they are convertible, use `try_rethrow!` to convert the inner error type.\n\nExample:\n\n```rust\n#[macro_use]\nextern crate trace_error;\n\nuse std::error::Error;\nuse std::fmt::{Display, Formatter, Result as FmtResult};\nuse std::io;\nuse std::fs::File;\n\nuse trace_error::TraceResult;\n\npub type MyResultType\u003cT\u003e = TraceResult\u003cT, MyErrorType\u003e;\n\n#[derive(Debug)]\npub enum MyErrorType {\n    Io(io::Error),\n    ErrorOne,\n    ErrorTwo,\n    //etc\n}\n\nimpl Display for MyErrorType {\n    fn fmt(\u0026self, f: \u0026mut Formatter) -\u003e FmtResult {\n        write!(f, \"{}\", self.description())\n    }\n}\n\nimpl Error for MyErrorType {\n    fn description(\u0026self) -\u003e \u0026str {\n        match *self {\n            MyErrorType::Io(ref err) =\u003e err.description(),\n            MyErrorType::ErrorOne =\u003e \"Error One\",\n            MyErrorType::ErrorTwo =\u003e \"Error Two\",\n        }\n    }\n}\n\nimpl From\u003cio::Error\u003e for MyErrorType {\n    fn from(err: io::Error) -\u003e MyErrorType {\n        MyErrorType::Io(err)\n    }\n}\n\nfn basic() -\u003e MyResultType\u003ci32\u003e {\n    Ok(42)\n}\n\nfn example() -\u003e MyResultType\u003c()\u003e {\n    // Note the use of try_rethrow! for TraceResult results\n    let meaning = try_rethrow!(basic());\n\n    // Prints 42 if `basic` succeeds\n    println!(\"{}\", meaning);\n\n    // Note the use of try_throw! for non-TraceResult results\n    let some_file = try_throw!(File::open(\"Cargo.toml\"));\n\n    Ok(())\n}\n\nfn main() {\n    match example() {\n        Ok(_) =\u003e println!(\"Success!\"),\n        // Here, err is the Trace\u003cE\u003e, which can be printed normally,\n        // showing both the error and the backtrace.\n        Err(err) =\u003e println!(\"Error: {}\", err)\n    }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnovacrazy%2Ftrace-error","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnovacrazy%2Ftrace-error","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnovacrazy%2Ftrace-error/lists"}