{"id":15417010,"url":"https://github.com/n3xed/embedded-error-chain","last_synced_at":"2025-06-10T16:32:17.916Z","repository":{"id":57624610,"uuid":"311196294","full_name":"N3xed/embedded-error-chain","owner":"N3xed","description":"A rust library implementing easy error handling for embedded devices with very little memory overhead.","archived":false,"fork":false,"pushed_at":"2021-01-12T18:15:36.000Z","size":57,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-05T03:08:00.436Z","etag":null,"topics":["embedded","error-handling","no-alloc","no-std","rust","rust-library"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/N3xed.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}},"created_at":"2020-11-09T01:53:10.000Z","updated_at":"2023-05-10T10:52:06.000Z","dependencies_parsed_at":"2022-08-26T22:21:50.697Z","dependency_job_id":null,"html_url":"https://github.com/N3xed/embedded-error-chain","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/N3xed%2Fembedded-error-chain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/N3xed%2Fembedded-error-chain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/N3xed%2Fembedded-error-chain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/N3xed%2Fembedded-error-chain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/N3xed","download_url":"https://codeload.github.com/N3xed/embedded-error-chain/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/N3xed%2Fembedded-error-chain/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259110482,"owners_count":22806726,"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":["embedded","error-handling","no-alloc","no-std","rust","rust-library"],"created_at":"2024-10-01T17:14:24.039Z","updated_at":"2025-06-10T16:32:17.885Z","avatar_url":"https://github.com/N3xed.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# embedded-error-chain\n\n[![build](https://github.com/N3xed/embedded-error-chain/workflows/CI/badge.svg)](https://github.com/N3xed/embedded-error-chain/actions)\n[![crates.io](https://img.shields.io/crates/v/embedded-error-chain.svg)](https://crates.io/crates/embedded-error-chain)\n[![docs](https://docs.rs/embedded-error-chain/badge.svg)](https://docs.rs/embedded-error-chain/)\n\nEasy error handling for embedded devices (no `liballoc` and `no_std`).\n\nErrors are represented by error codes and come from enums that implement the\n`ErrorCategory` trait (a derive macro exists), which is used for custom debug\nprinting per error code among other things. Each error code can have a value from `0`\nto `15` (4 bits) and you can chain an error with up to four different error codes of\ndifferent categories.\n\nThe `Error` type encapsulates an error code and error chain, and is only a single\n`u32` in size. There is also an untyped `DynError` type, which unlike `Error`\ndoes not have a type parameter for the current error code. Its size is a `u32` +\npointer (`usize`), which can be used to forward source errors of different categories\nto the caller.\n\nThis library was inspired by libraries such as\n[error-chain](https://crates.io/crates/error-chain),\n[anyhow](https://crates.io/crates/anyhow) and\n[thiserror](https://crates.io/crates/thiserror), though it was made to work in `no_std`\n**and** no `liballoc` environments with very little memory overhead.\n\n## Example\n```rust\nuse embedded_error_chain::prelude::*;\n\n#[derive(Clone, Copy, ErrorCategory)]\n#[repr(u8)]\nenum SpiError {\n    BusError,\n    // ...\n}\n\nstatic LAST_GYRO_ACC_READOUT: usize = 200;\n\n#[derive(Clone, Copy, ErrorCategory)]\n#[error_category(links(SpiError))]\n#[repr(u8)]\nenum GyroAccError {\n    InitFailed,\n\n    #[error(\"{variant} (readout={})\", LAST_GYRO_ACC_READOUT)]\n    ReadoutFailed,\n\n    /// Value must be in range [0, 256)\n    #[error(\"{variant}: {summary}\")]\n    InvalidValue,\n}\n\nfn main() {\n    if let Err(err) = calibrate() {\n        // log the error\n        println!(\"{:?}\", err);\n        // ...\n    }\n\n    let readout = match gyro_acc_readout() {\n        Ok(val) =\u003e val,\n        Err(err) =\u003e {\n            if let Some(spi_error) = err.code_of_category::\u003cSpiError\u003e() {\n                // try to fix it\n                0\n            }\n            else {\n                panic!(\"unfixable spi error\");\n            }\n        }\n    };\n}\n\nfn spi_init() -\u003e Result\u003c(), SpiError\u003e {\n    Err(SpiError::BusError)\n}\n\nfn gyro_acc_init() -\u003e Result\u003c(), Error\u003cGyroAccError\u003e\u003e {\n    spi_init().chain_err(GyroAccError::InitFailed)?;\n    Ok(())\n}\n\nfn gyro_acc_readout() -\u003e Result\u003cu32, Error\u003cGyroAccError\u003e\u003e {\n    Err(SpiError::BusError.chain(GyroAccError::InvalidValue))\n}\n\nfn calibrate() -\u003e Result\u003c(), DynError\u003e {\n    gyro_acc_init()?;\n    // other stuff...\n    Ok(())\n}\n```\n\nLicense: MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fn3xed%2Fembedded-error-chain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fn3xed%2Fembedded-error-chain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fn3xed%2Fembedded-error-chain/lists"}