{"id":13412758,"url":"https://github.com/emperror/errors","last_synced_at":"2026-03-11T13:06:17.324Z","repository":{"id":37844764,"uuid":"196009910","full_name":"emperror/errors","owner":"emperror","description":"Drop-in replacement for the standard library errors package and github.com/pkg/errors","archived":false,"fork":false,"pushed_at":"2022-06-20T01:43:12.000Z","size":181,"stargazers_count":198,"open_issues_count":10,"forks_count":14,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-06T18:52:44.337Z","etag":null,"topics":["error","errors","stacktrace"],"latest_commit_sha":null,"homepage":"https://emperror.dev/errors","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/emperror.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2019-07-09T13:02:52.000Z","updated_at":"2025-02-25T23:00:52.000Z","dependencies_parsed_at":"2022-07-12T17:02:13.290Z","dependency_job_id":null,"html_url":"https://github.com/emperror/errors","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emperror%2Ferrors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emperror%2Ferrors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emperror%2Ferrors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emperror%2Ferrors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emperror","download_url":"https://codeload.github.com/emperror/errors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243625166,"owners_count":20321248,"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":["error","errors","stacktrace"],"created_at":"2024-07-30T20:01:28.815Z","updated_at":"2026-03-11T13:06:12.300Z","avatar_url":"https://github.com/emperror.png","language":"Go","readme":"# Emperror: Errors [![Mentioned in Awesome Go](https://awesome.re/mentioned-badge-flat.svg)](https://github.com/avelino/awesome-go#error-handling)\n\n[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/emperror/errors/CI?style=flat-square)](https://github.com/emperror/errors/actions?query=workflow%3ACI)\n[![Codecov](https://img.shields.io/codecov/c/github/emperror/errors?style=flat-square)](https://codecov.io/gh/emperror/errors)\n[![Go Report Card](https://goreportcard.com/badge/emperror.dev/errors?style=flat-square)](https://goreportcard.com/report/emperror.dev/errors)\n![Go Version](https://img.shields.io/badge/go%20version-%3E=1.12-61CFDD.svg?style=flat-square)\n[![PkgGoDev](https://pkg.go.dev/badge/mod/emperror.dev/errors)](https://pkg.go.dev/mod/emperror.dev/errors)\n[![FOSSA Status](https://app.fossa.com/api/projects/custom%2B8125%2Femperror.dev%2Ferrors.svg?type=shield)](https://app.fossa.com/projects/custom%2B8125%2Femperror.dev%2Ferrors?ref=badge_shield)\n\n\n**Drop-in replacement for the standard library `errors` package and [github.com/pkg/errors](https://github.com/pkg/errors).**\n\nThis is a single, lightweight library merging the features of standard library `errors` package\nand [github.com/pkg/errors](https://github.com/pkg/errors). It also backports a few features\n(like Go 1.13 error handling related features).\n\nStandard library features:\n- `New` creates an error with stack trace\n- `Unwrap` supports both Go 1.13 wrapper (`interface { Unwrap() error }`) and **pkg/errors** causer (`interface { Cause() error }`) interface\n- Backported `Is` and `As` functions\n\n[github.com/pkg/errors](https://github.com/pkg/errors) features:\n- `New`, `Errorf`, `WithMessage`, `WithMessagef`, `WithStack`, `Wrap`, `Wrapf` functions behave the same way as in the original library\n- `Cause` supports both Go 1.13 wrapper (`interface { Unwrap() error }`) and **pkg/errors** causer (`interface { Cause() error }`) interface\n\nAdditional features:\n- `NewPlain` creates a new error without any attached context, like stack trace\n- `Sentinel` is a shorthand type for creating [constant error](https://dave.cheney.net/2016/04/07/constant-errors)\n- `WithStackDepth` allows attaching stack trace with a custom caller depth\n- `WithStackDepthIf`, `WithStackIf`, `WrapIf`, `WrapIff` only annotate errors with a stack trace if there isn't one already in the error chain\n- Multi error aggregating multiple errors into a single value\n- `NewWithDetails`, `WithDetails` and `Wrap*WithDetails` functions to add key-value pairs to an error\n- Match errors using the `match` package\n\n\n## Installation\n\n```bash\ngo get emperror.dev/errors\n```\n\n\n## Usage\n\n```go\npackage main\n\nimport \"emperror.dev/errors\"\n\n// ErrSomethingWentWrong is a sentinel error which can be useful within a single API layer.\nconst ErrSomethingWentWrong = errors.Sentinel(\"something went wrong\")\n\n// ErrMyError is an error that can be returned from a public API.\ntype ErrMyError struct {\n\tMsg string\n}\n\nfunc (e ErrMyError) Error() string {\n\treturn e.Msg\n}\n\nfunc foo() error {\n\t// Attach stack trace to the sentinel error.\n\treturn errors.WithStack(ErrSomethingWentWrong)\n}\n\nfunc bar() error {\n\treturn errors.Wrap(ErrMyError{\"something went wrong\"}, \"error\")\n}\n\nfunc main() {\n\tif err := foo(); err != nil {\n\t\tif errors.Cause(err) == ErrSomethingWentWrong { // or errors.Is(ErrSomethingWentWrong)\n\t\t\t// handle error\n\t\t}\n\t}\n\n\tif err := bar(); err != nil {\n\t\tif errors.As(err, \u0026ErrMyError{}) {\n\t\t\t// handle error\n\t\t}\n\t}\n}\n```\n\nMatch errors:\n\n```go\npackage main\n\nimport (\n    \"emperror.dev/errors\"\n    \"emperror.dev/errors/match\"\n)\n\n// ErrSomethingWentWrong is a sentinel error which can be useful within a single API layer.\nconst ErrSomethingWentWrong = errors.Sentinel(\"something went wrong\")\n\ntype clientError interface{\n    ClientError() bool\n}\n\nfunc foo() error {\n\t// Attach stack trace to the sentinel error.\n\treturn errors.WithStack(ErrSomethingWentWrong)\n}\n\nfunc main() {\n    var ce clientError\n    matcher := match.Any{match.As(\u0026ce), match.Is(ErrSomethingWentWrong)}\n\n\tif err := foo(); err != nil {\n\t\tif matcher.MatchError(err) {\n\t\t\t// you can use matchers to write complex conditions for handling (or not) an error\n            // used in emperror\n\t\t}\n\t}\n}\n```\n\n\n## Development\n\nContributions are welcome! :)\n\n1. Clone the repository\n1. Make changes on a new branch\n1. Run the test suite:\n    ```bash\n    ./pleasew build\n    ./pleasew test\n    ./pleasew gotest\n    ./pleasew lint\n    ```\n1. Commit, push and open a PR\n\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE) for more information.\n\nCertain parts of this library are inspired by (or entirely copied from) various third party libraries.\nTheir licenses can be found in the [Third Party License File](LICENSE_THIRD_PARTY).\n\n[![FOSSA Status](https://app.fossa.com/api/projects/custom%2B8125%2Femperror.dev%2Ferrors.svg?type=large)](https://app.fossa.com/projects/custom%2B8125%2Femperror.dev%2Ferrors?ref=badge_large)\n","funding_links":[],"categories":["Error Handling","Go","错误处理","Relational Databases","错误处理`go 语言错误处理库`"],"sub_categories":["Search and Analytic Databases","Advanced Console UIs","检索及分析资料库","SQL 查询语句构建库"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femperror%2Ferrors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femperror%2Ferrors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femperror%2Ferrors/lists"}