{"id":32705179,"url":"https://github.com/miaan15/zig-exception","last_synced_at":"2026-06-11T16:32:07.325Z","repository":{"id":320717844,"uuid":"1083115439","full_name":"miaan15/zig-exception","owner":"miaan15","description":"A small generic result/exception wrapper for Zig","archived":false,"fork":false,"pushed_at":"2026-03-04T10:44:49.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-04T17:40:54.133Z","etag":null,"topics":["error-handling","exception-handling","zig"],"latest_commit_sha":null,"homepage":"","language":"Zig","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/miaan15.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-25T11:29:06.000Z","updated_at":"2026-03-04T10:44:53.000Z","dependencies_parsed_at":"2025-10-25T13:23:52.930Z","dependency_job_id":"9c89c09b-ae6c-40d1-92bf-62ae47e41fbb","html_url":"https://github.com/miaan15/zig-exception","commit_stats":null,"previous_names":["miaan15/zig-exception"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/miaan15/zig-exception","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miaan15%2Fzig-exception","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miaan15%2Fzig-exception/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miaan15%2Fzig-exception/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miaan15%2Fzig-exception/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/miaan15","download_url":"https://codeload.github.com/miaan15/zig-exception/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miaan15%2Fzig-exception/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34208762,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-11T02:00:06.485Z","response_time":57,"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-handling","exception-handling","zig"],"created_at":"2025-11-02T01:01:35.953Z","updated_at":"2026-06-11T16:32:07.312Z","avatar_url":"https://github.com/miaan15.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"oh god this should be named \"expected\" because it is how c++ name but f* that\n\n# zig-exception\n\nA small generic result/exception wrapper for [Zig](https://ziglang.org).  \nIt allows you to wrap a success-value type and an error tag + payload, similar to `std::exception` in C++.\n\n### Features\n\n- Define `Exception(T, ETag, EPayload)`:\n  - `T` = the success type  \n  - `ETag` = an error tag type (e.g. an `error{…}` enum)  \n  - `EPayload` = an arbitrary payload type carried along with errors  \n- Construct:\n  - `.ok(value)` → success  \n  - `.err(tag, payload)` → error  \n- Accessors:\n  - `.get()` → returns `ETag!T` (i.e. either success value or error tag)  \n  - `.get_ok()` → returns `!T` (error if trying to get ok from an error)  \n  - `.get_err()` → returns `!E` (where `E` contains tag + payload; error if trying on an ok)  \n\n### Demo \u0026 Test\n\n```bash\nzig build run\nzig build test\n```\n\n### Example\n\n```zig\nconst std = @import(\"std\");\nconst Exception = @import(\"exception\").Exception;\n\nconst MyError = error{ Zero, Negetive };\n\n// result might be i32 if success; return MyError and message if error:\nconst ResultI32 = Exception(i32, MyError, []const u8);\n\npub fn foo(x: i32) ResultI32 {\n    if (x \u003c 0) {\n        return ResultI32.err(MyError.Negetive, \"x was negative\");\n    }\n    if (x == 0) {\n        return ResultI32.err(MyError.Zero, \"x was zero\");\n    }\n    return ResultI32.ok(x * 2);\n}\n\npub fn main() !void {\n    // expect error\n    const r1 = foo(-5);\n    std.debug.print(\"Case: x = -5\\n\", .{});\n    if (r1.get()) |ok_val| {\n        std.debug.print(\"Success value (x * 2): {d}\\n\", .{ok_val});\n    } else |err_tag| {\n        std.debug.print(\"Error tag: {s}\\n\", .{@errorName(err_tag)});\n        const err_info = try r1.get_err();\n        std.debug.print(\"  payload: \\\"{s}\\\"\\n\", .{err_info.payload});\n    }\n\n    // expect success\n    const r2 = foo(10);\n    std.debug.print(\"\\nCase: x = 10\\n\", .{});\n\n    const val = r2.get() catch |e| {\n        std.debug.print(\"Error tag: {s}\\n\", .{@errorName(e)});\n        return;\n    };\n    std.debug.print(\"Success value (x * 2): {d}\\n\", .{val});\n}\n```\n```\nCase: x = -5\nError tag: Negetive\n  payload: \"x was negative\"\n\nCase: x = 10\nSuccess value (x * 2): 20\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiaan15%2Fzig-exception","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmiaan15%2Fzig-exception","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiaan15%2Fzig-exception/lists"}