{"id":41913513,"url":"https://github.com/xybor-x/xyerror","last_synced_at":"2026-01-25T16:15:54.416Z","repository":{"id":58465603,"uuid":"531350980","full_name":"xybor-x/xyerror","owner":"xybor-x","description":"Python-like error design in Golang","archived":false,"fork":false,"pushed_at":"2023-01-07T16:06:43.000Z","size":24,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"dev","last_synced_at":"2024-09-23T06:07:27.002Z","etag":null,"topics":["error","error-handling","errors","exception-handling","golang","golang-error","golang-errors","golang-library","python-like"],"latest_commit_sha":null,"homepage":"","language":"Go","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/xybor-x.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-01T03:37:42.000Z","updated_at":"2022-10-13T12:29:03.000Z","dependencies_parsed_at":"2023-02-07T14:47:26.054Z","dependency_job_id":null,"html_url":"https://github.com/xybor-x/xyerror","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/xybor-x/xyerror","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xybor-x%2Fxyerror","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xybor-x%2Fxyerror/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xybor-x%2Fxyerror/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xybor-x%2Fxyerror/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xybor-x","download_url":"https://codeload.github.com/xybor-x/xyerror/tar.gz/refs/heads/dev","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xybor-x%2Fxyerror/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28755125,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-25T13:59:49.818Z","status":"ssl_error","status_checked_at":"2026-01-25T13:59:33.728Z","response_time":113,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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-handling","errors","exception-handling","golang","golang-error","golang-errors","golang-library","python-like"],"created_at":"2026-01-25T16:15:54.313Z","updated_at":"2026-01-25T16:15:54.408Z","avatar_url":"https://github.com/xybor-x.png","language":"Go","readme":"[![Xybor founder](https://img.shields.io/badge/xybor-huykingsofm-red)](https://github.com/huykingsofm)\n[![Go Reference](https://pkg.go.dev/badge/github.com/xybor-x/xyerror.svg)](https://pkg.go.dev/github.com/xybor-x/xyerror)\n[![GitHub Repo stars](https://img.shields.io/github/stars/xybor-x/xyerror?color=yellow)](https://github.com/xybor-x/xyerror)\n[![GitHub top language](https://img.shields.io/github/languages/top/xybor-x/xyerror?color=lightblue)](https://go.dev/)\n[![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/xybor-x/xyerror)](https://go.dev/blog/go1.18)\n[![GitHub release (release name instead of tag name)](https://img.shields.io/github/v/release/xybor-x/xyerror?include_prereleases)](https://github.com/xybor-x/xyerror/releases/latest)\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/5fae4ad52c184d6dbec00f44312f20d6)](https://www.codacy.com/gh/xybor-x/xyerror/dashboard?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=xybor-x/xyerror\u0026utm_campaign=Badge_Grade)\n[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/5fae4ad52c184d6dbec00f44312f20d6)](https://www.codacy.com/gh/xybor-x/xyerror/dashboard?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=xybor-x/xyerror\u0026utm_campaign=Badge_Coverage)\n[![Go Report](https://goreportcard.com/badge/github.com/xybor-x/xyerror)](https://goreportcard.com/report/github.com/xybor-x/xyerror)\n\n# Introduction\n\nPackage xyerror supports to define and compare errors conveniently.\n\nThe error is inspired by Python `Exception`.\n\n# Features\n\nPackage xyerror defined an error type used to create other errors called\n`Exception`, it is equivalent to `Exception` class in Python.\n\n`Exception` creates `Error` objects by using `New` or `Newf` method. It looks\nlike `Exception` class creates `Exception` instances. Example:\n\n```golang\n// xyerror\nvar err xyerror.Error = xyerror.ValueError.New(\"value is invalid\")\nfmt.Println(err)\n```\n\n```python\n# python\nprint(ValueError(\"value is invalid\"))\n```\n\nAn `Exception` can \"inherits\" from another `Exception`. Example:\n\n```golang\n// xyerror\nvar ZeroDivisionError = xyerror.ValueError.NewException(\"ZeroDivisionError\")\nfmt.Println(ZeroDivisionError.New(\"do not divide by zero\"))\n```\n\n```python\n# python\nclass ZeroDivisionError(ValueError):\n    ...\nprint(ZeroDivisionError(\"do not divide by zero\"))\n```\n\nAn `Exception` also \"inherits\" from many `Exception` instances. Example:\n\n```golang\n// xyerror\nvar ValueTypeError = xyerror.\n    Combine(xyerror.ValueError, xyerror.TypeError).\n    NewException(\"ValueTypeError\")\n```\n\n```python\n# python\nclass ValueTypeError(ValueError, TypeError):\n    ...\n```\n\nAn `Error` created by an `Exception` can compare to that `Exception`.\n\n```golang\n// xyerror\nfunc foo() error {\n    return xyerror.ValueError.New(\"value is invalid\")\n}\n\nfunc bar() error {\n    if err := foo(); errors.Is(err, xyerror.ValueError) {\n        fmt.Println(err)\n    } else {\n        return err\n    }\n    return nil\n}\n```\n\n```python\n# python\ndef foo():\n    raise ValueError(\"value is invalid\")\n\ndef bar():\n    try:\n        foo()\n    except ValueError as e:\n        print(e)\n```\n\n# Example\n\n```golang\npackage xyerror_test\n\nimport (\n    \"errors\"\n    \"fmt\"\n\n    \"github.com/xybor-x/xyerror\"\n)\n\nfunc ExampleException() {\n    // To create a root Exception, call xyerror.NewException with the its name.\n    var RootError = xyerror.NewException(\"RootError\")\n\n    // You can create an Exception by inheriting from another one.\n    var ChildError = RootError.NewException(\"ChildError\")\n\n    fmt.Println(RootError)\n    fmt.Println(ChildError)\n\n    // Output:\n    // RootError\n    // ChildError\n}\n\nfunc ExampleError() {\n    // You can compare an Error with an Exception by using the built-in method\n    // errors.Is.\n    var NegativeIndexError = xyerror.IndexError.NewException(\"NegativeIndexError\")\n\n    var err1 = xyerror.ValueError.New(\"some value error\")\n    if errors.Is(err1, xyerror.ValueError) {\n        fmt.Println(\"err1 is a ValueError\")\n    }\n    if !errors.Is(err1, NegativeIndexError) {\n        fmt.Println(\"err1 is not a NegativeIndexError\")\n    }\n\n    var err2 = NegativeIndexError.Newf(\"some negative index error %d\", -1)\n    if errors.Is(err2, NegativeIndexError) {\n        fmt.Println(\"err2 is a NegativeIndexError\")\n    }\n    if errors.Is(err2, xyerror.IndexError) {\n        fmt.Println(\"err2 is a IndexError\")\n    }\n    if !errors.Is(err2, xyerror.ValueError) {\n        fmt.Println(\"err2 is not a ValueError\")\n    }\n\n    // Output:\n    // err1 is a ValueError\n    // err1 is not a NegativeIndexError\n    // err2 is a NegativeIndexError\n    // err2 is a IndexError\n    // err2 is not a ValueError\n}\n\nfunc ExampleCombinedException() {\n    // CombinedException allows you to create an Exception with multiparents.\n    var KeyValueError = xyerror.\n        Combine(xyerror.KeyError, xyerror.ValueError).\n        NewException(\"KeyValueError\")\n\n    var err = KeyValueError.New(\"something is wrong\")\n\n    if errors.Is(err, xyerror.KeyError) {\n        fmt.Println(\"err is a KeyError\")\n    }\n\n    if errors.Is(err, xyerror.ValueError) {\n        fmt.Println(\"err is a ValueError\")\n    }\n\n    // Output:\n    // err is a KeyError\n    // err is a ValueError\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxybor-x%2Fxyerror","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxybor-x%2Fxyerror","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxybor-x%2Fxyerror/lists"}