{"id":21199179,"url":"https://github.com/r167/errunwrap","last_synced_at":"2026-04-28T19:34:09.682Z","repository":{"id":211966372,"uuid":"730384768","full_name":"R167/errunwrap","owner":"R167","description":"Check for errors which wrap other errors without implementing the Unwrap methods.","archived":false,"fork":false,"pushed_at":"2023-12-23T17:52:26.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-01T21:07:34.977Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/R167.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":"2023-12-11T20:08:32.000Z","updated_at":"2023-12-11T20:12:09.000Z","dependencies_parsed_at":"2025-01-21T14:43:29.994Z","dependency_job_id":"a39e9780-9aff-4604-8131-5266c3465e78","html_url":"https://github.com/R167/errunwrap","commit_stats":null,"previous_names":["r167/errunwrap"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/R167/errunwrap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/R167%2Ferrunwrap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/R167%2Ferrunwrap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/R167%2Ferrunwrap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/R167%2Ferrunwrap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/R167","download_url":"https://codeload.github.com/R167/errunwrap/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/R167%2Ferrunwrap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32396244,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T14:34:11.604Z","status":"ssl_error","status_checked_at":"2026-04-28T14:32:37.009Z","response_time":56,"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":[],"created_at":"2024-11-20T19:59:35.232Z","updated_at":"2026-04-28T19:34:09.646Z","avatar_url":"https://github.com/R167.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# errunwrap\n\n[![CI](https://github.com/R167/errunwrap/actions/workflows/ci.yaml/badge.svg)](https://github.com/R167/errunwrap/actions/workflows/ci.yaml) [![Go Reference](https://pkg.go.dev/badge/github.com/R167/errunwrap.svg)](https://pkg.go.dev/github.com/R167/errunwrap) [![Go Report Card](https://goreportcard.com/badge/github.com/R167/errunwrap)](https://goreportcard.com/report/github.com/R167/errunwrap)\n\nCheck for errors which wrap other errors without implementing the Unwrap method.\n\n[Go 1.13](https://go.dev/blog/go1.13-errors) introduced new features in the `errors` package with\nthe `Unwrap() error` method. This allows types of the form `type MyCustomError struct { error }` to\nattach additional semantic meaning and context to errors. However, to use this functionality\ncorrectly, in addition to the cases [errorlint](https://github.com/polyfloyd/go-errorlint) catches\nto ensure error comparison is done using `errors.Is` and `errors.As`, developers must ALSO remember\nto implement the `Unwrap() error` (or in go 1.20, `Unwrap() []error` if it wraps multiple errors)\n\n## Usage\n\n```bash\ngo install github.com/R167/errunwrap@latest\n\n# Run the linter. Accepts standard go package specs\nerrunwrap ./...\n\n# Run the linter in strict mode. This ensures any errors which wrap multiple\n# errors implement Unwrap() []error\nerrunwrap -strict-unwrap ./...\n```\n\nIf you want to run this along with other linters, you can use the analyzer itself\n`github.com/R167/errunwrap/passes/errunwrap`. Refer to golang.org/x/tools/go/analysis for more\ninformation on how to use analyzers.\n\n## Examples\n\n### Missing Unwrap\n\nErrors which wrap other errors without implementing the `Unwrap() error` method will cause\n`errors.Is` and `errors.As` to fail to traverse the error chain.\n\n```go\ntype MissingUnwrapError { // linter will fail b/c Unwrap() is not implemented\n  error\n}\n\n// errors.Is will fail to traverse the error chain\nif errors.Is(MissingUnwrapError{error: ErrRowNotFound}, ErrRowNotFound) {\n  // This code will never be reached\n}\n```\n\n### Strict Unwrap\n\nWhen using `-strict-unwrap`, the linter will enforce that errors which wrap multiple errors\n(e.g. `type MultiError []error`) implement `Unwrap() []error` instead of `Unwrap() error`. This\nallows `errors.Is` and `errors.As` to traverse the full error tree.\n\n```go\n// with -strict-unwrap\ntype MultiError []error\n\nfunc (e MultiError) Unwrap() error { // linter will fail b/c Unwrap() error\n  return e[0]\n}\n```\n\n### Full example\n\n```go\nvar ErrRowNotFound = errors.New(\"record is missing in the DB, but that's okay sometimes\")\n\ntype MissingUnwrapError { // linter will fail b/c Unwrap() is not implemented\n  error\n}\n\ntype StatusError struct {\n  Err        error\n  StatusCode int\n}\n\nfunc (e StatusError) Unwrap() error {\n  return e.Err\n}\n\nfunc (e StatusError) Error() string {\n  return fmt.Sprintf(\"%d: %s\", e.StatusCode, e.Err)\n}\n\nfunc handleRequest() int {\n  var err error = MissingUnwrapError{\n    error: StatusError{\n      error: ErrBad\n      StatusCode: 418\n    }\n  }\n\n  if err == nil {\n    return 200\n  }\n\n  if errors.Is(err, ErrRowNotFound) {\n    // UH OH! b/c MissingUnwrapError doesn't implement Unwrap() error,\n    // we will NEVER hit this code branch\n    // errors.Is is unable to look inside the contents of StatusError.error\n    return http.StatusNotFound\n  }\n  var statusErr StatusError\n  if errors.As(err, \u0026StatusError) {\n    // OH NO AGAIN! Once again MissingUnwrapError foils us from inspecting the status code :sadpanda:\n    return statusErr.StatusCode\n  }\n\n  // Fallback to general purpose error code\n  return 500\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr167%2Ferrunwrap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fr167%2Ferrunwrap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr167%2Ferrunwrap/lists"}