{"id":15343637,"url":"https://github.com/jmjoy/except","last_synced_at":"2025-08-25T06:40:18.560Z","repository":{"id":72164795,"uuid":"208542635","full_name":"jmjoy/except","owner":"jmjoy","description":"The only one `Error`.","archived":false,"fork":false,"pushed_at":"2023-06-01T10:35:06.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-16T00:49:42.169Z","etag":null,"topics":["error","error-handler","exception","panic","throw","try","try-catch"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/except","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jmjoy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-15T04:39:01.000Z","updated_at":"2023-06-01T10:26:31.000Z","dependencies_parsed_at":"2023-12-08T13:00:17.368Z","dependency_job_id":null,"html_url":"https://github.com/jmjoy/except","commit_stats":{"total_commits":8,"total_committers":2,"mean_commits":4.0,"dds":0.375,"last_synced_commit":"e12747a9e0c8e2d11cff59a93433484d4b0a99ed"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/jmjoy/except","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmjoy%2Fexcept","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmjoy%2Fexcept/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmjoy%2Fexcept/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmjoy%2Fexcept/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jmjoy","download_url":"https://codeload.github.com/jmjoy/except/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmjoy%2Fexcept/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271097626,"owners_count":24698721,"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","status":"online","status_checked_at":"2025-08-19T02:00:09.176Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["error","error-handler","exception","panic","throw","try","try-catch"],"created_at":"2024-10-01T10:48:01.847Z","updated_at":"2025-08-25T06:40:18.507Z","avatar_url":"https://github.com/jmjoy.png","language":"Rust","readme":"# Except\n\nThe only one `Error`.\n\n**only available in nightly toolchain now.**\n\n## Why?\n\nThe official error handling method of Rust is `Result\u003cT, E\u003e where E: Error`.\n\nBut Error is too complicated, various types need to be converted, and each crate has its own set of Error.\n\nEven worse, enum nesting will occur, such as:\n\n```rust\nenum BazError {\n    IO(std::io::Error),\n}\n\nenum BarError {\n    IO(std::io::Error),\n    Baz(BazError),\n}\n\nenum FooError {\n    IO(std::io::Error),\n    Bar(BarError),\n}\n```\n\nHow many times `std::io::Error` occurs here?\n\nThe [`anyhow::Error`](https://crates.io/crates/anyhow) is good, but it is generally only used for \napplication.\n\n## Solution\n\n*This is just a personal opinion.*\n\nAn Error actually only contains the following elements:\n\n- `type`: Auto generated id, used to determine whether the Error is a certain type.\n- `sub_type`: Auto generated id, used to determine whether the Error is a certain sub type, used to supplement type.\n- `message`: String describing the Error.\n- `data`: Optional Error data.\n- `backtrace`: Error call stack.\n- `source`: Optional previous Error.\n\nFor Rust, the `message`, ~~`backtrace`,~~ `source` already exists in `std::error::Error`.\n\nThen I prefer to auto generate the `type`, I think `TypeId` is a solution.\n\nFor `data`, I don't have the best idea, because it may be of any type. In order to achieve\nonly one Error, I chose to use `Box\u003cdyn Any\u003e` internally to save it.\n\n## Example\n\n```rust\nuse except::ErrorBuilder;\n\npub struct MyErrorKind;\n\npub fn foo() -\u003e except::Result\u003c()\u003e {\n    Err(ErrorBuilder::new::\u003cMyErrorKind\u003e().message(\"this is my error\").build())\n}\n\npub fn main() {\n    if let Err(ex) = foo() {\n        if ex.is::\u003cMyErrorKind\u003e() {\n            eprintln!(\"my error detected: {:?}\", ex);\n        }\n    }\n}\n```\n\n## License\n\nApache-2.0\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmjoy%2Fexcept","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjmjoy%2Fexcept","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmjoy%2Fexcept/lists"}