{"id":38743904,"url":"https://github.com/electrofocus/errchain","last_synced_at":"2026-01-17T11:42:43.473Z","repository":{"id":57704013,"uuid":"496883867","full_name":"electrofocus/errchain","owner":"electrofocus","description":"Go package for errors chaining for further examining using standard errors.Is and errors.As functions","archived":false,"fork":false,"pushed_at":"2023-02-11T12:58:12.000Z","size":26,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-19T23:15:08.678Z","etag":null,"topics":["errors","go","go-errors","golang","golang-errors","golang-package"],"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/electrofocus.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":"2022-05-27T06:17:38.000Z","updated_at":"2023-05-29T17:26:48.000Z","dependencies_parsed_at":"2023-02-17T16:10:18.297Z","dependency_job_id":null,"html_url":"https://github.com/electrofocus/errchain","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/electrofocus/errchain","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/electrofocus%2Ferrchain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/electrofocus%2Ferrchain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/electrofocus%2Ferrchain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/electrofocus%2Ferrchain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/electrofocus","download_url":"https://codeload.github.com/electrofocus/errchain/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/electrofocus%2Ferrchain/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28508262,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T10:25:30.148Z","status":"ssl_error","status_checked_at":"2026-01-17T10:25:29.718Z","response_time":85,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["errors","go","go-errors","golang","golang-errors","golang-package"],"created_at":"2026-01-17T11:42:43.347Z","updated_at":"2026-01-17T11:42:43.431Z","avatar_url":"https://github.com/electrofocus.png","language":"Go","readme":"# errchain\n\n❗️ This package is no longer needed if you are using Go version \u003e= 1.20, since [in 1.20 standard errors package was extended](https://go.dev/doc/go1.20#errors) by adding [`Join`](https://pkg.go.dev/errors#Join) method, which provides functionality similar to that provided by errchain package.\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/electrofocus/errchain.svg)](https://pkg.go.dev/github.com/electrofocus/errchain)\n\n## About\n\nHere's [Go](https://go.dev) package for errors chaining for further examining using the standard `errors.Is`. You can learn more about working with errors in Go in [this](https://go.dev/blog/go1.13-errors) article. Explore [example](#examples) below for more understanding.\n\nThis package uses [module version numbering](https://go.dev/doc/modules/version-numbers).\n\n\n## Install\nWith a [correctly configured](https://golang.org/doc/install#testing) Go toolchain run:\n\n```\ngo get github.com/electrofocus/errchain\n```\n\n## Examples\n\n### Chain and examine\nLet's build new error from multiple errors and examine it with `errors.Is`:\n\n```go\npackage main\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"io\"\n\t\"net/http\"\n\t\"os\"\n\n\t\"github.com/electrofocus/errchain\"\n)\n\nfunc main() {\n\tvar (\n\t\tmyErr = errors.New(\"my err\")\n\t\terr   = errchain.New(myErr, io.EOF, os.ErrClosed, http.ErrHijacked)\n\t)\n\n\tif errors.Is(err, io.EOF) {\n\t\tfmt.Printf(\"here we have %q error\\n\", io.EOF)\n\t}\n\n\tif errors.Is(err, myErr) {\n\t\tfmt.Printf(\"and %q error\\n\", myErr)\n\t}\n\n\tif errors.Is(err, os.ErrClosed) {\n\t\tfmt.Printf(\"and %q error\\n\", os.ErrClosed)\n\t}\n\n\tif errors.Is(err, http.ErrHijacked) {\n\t\tfmt.Printf(\"and %q error,\\n\", http.ErrHijacked)\n\t}\n\n\tif !errors.Is(err, http.ErrAbortHandler) {\n\t\tfmt.Printf(\"but don't have %q error\\n\", http.ErrAbortHandler)\n\t}\n}\n```\n\nOpen above example in [The Go Playground](https://go.dev/play/p/yfPyoY_yVPi).\n\n### Check error for compliance with one of expected errors\nMoreover, non-obvious potential of `errchain` package is the ability to examine an error for compliance with one of expected ones.\n\nLet's declare a `toy` function, as a result of which we expect an `error` (in fact, it will always return `io.EOF`):\n```go\nimport \"encoding/json\"\n\nfunc toy() error {\n\treturn io.EOF\n}\n```\n\nSometimes you expect several different errors. In this case, to recognize the returned error, you need to do something like this:\n```go\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"net/http\"\n\t\"os\"\n)\n\nfunc main() {\n\tif err := toy(); err != nil \u0026\u0026\n\t\t(errors.Is(err, os.ErrClosed) ||\n\t\t\terrors.Is(err, io.EOF) ||\n\t\t\terrors.Is(err, http.ErrHijacked)) {\n\n\t\tfmt.Printf(\"got one of expected errors: %q\\n\", err)\n\t}\n}\n```\n\nAn equivalent check can be performed using `errors.Is` and `errchain` package's `New` functions, but in more concise and convinient way:\n```go\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"net/http\"\n\t\"os\"\n\t\n\t\"github.com/electrofocus/errchain\"\n)\n\nfunc main() {\n\tif err := toy(); errors.Is(errchain.New(\n\t\tos.ErrClosed,\n\t\tio.EOF,\n\t\thttp.ErrHijacked,\n\t), err) {\n\t\tfmt.Printf(\"got one of expected errors: %q\\n\", err)\n\t}\n}\n```\n\nPlay with above example in [The Go Playground](https://go.dev/play/p/LwaRS9gB1Bn).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felectrofocus%2Ferrchain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felectrofocus%2Ferrchain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felectrofocus%2Ferrchain/lists"}