{"id":13412776,"url":"https://github.com/hashicorp/go-multierror","last_synced_at":"2025-05-13T15:02:58.290Z","repository":{"id":24644537,"uuid":"28054085","full_name":"hashicorp/go-multierror","owner":"hashicorp","description":"A Go (golang) package for representing a list of errors as a single error.","archived":false,"fork":false,"pushed_at":"2025-03-13T12:38:11.000Z","size":105,"stargazers_count":2453,"open_issues_count":30,"forks_count":129,"subscribers_count":300,"default_branch":"main","last_synced_at":"2025-05-05T22:26:57.877Z","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":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hashicorp.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":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-12-15T20:12:26.000Z","updated_at":"2025-05-05T06:01:58.000Z","dependencies_parsed_at":"2023-10-02T20:28:45.903Z","dependency_job_id":"55539900-a477-40ab-8a51-7dcac0ac9460","html_url":"https://github.com/hashicorp/go-multierror","commit_stats":{"total_commits":72,"total_committers":24,"mean_commits":3.0,"dds":0.6805555555555556,"last_synced_commit":"6fa16eae919d27fdd2a107373fff9388795a6802"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashicorp%2Fgo-multierror","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashicorp%2Fgo-multierror/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashicorp%2Fgo-multierror/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashicorp%2Fgo-multierror/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hashicorp","download_url":"https://codeload.github.com/hashicorp/go-multierror/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253968241,"owners_count":21992253,"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":[],"created_at":"2024-07-30T20:01:29.061Z","updated_at":"2025-05-13T15:02:58.269Z","avatar_url":"https://github.com/hashicorp.png","language":"Go","readme":"# go-multierror\n\n[![CircleCI](https://img.shields.io/circleci/build/github/hashicorp/go-multierror/master)](https://circleci.com/gh/hashicorp/go-multierror)\n[![Go Reference](https://pkg.go.dev/badge/github.com/hashicorp/go-multierror.svg)](https://pkg.go.dev/github.com/hashicorp/go-multierror)\n![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/hashicorp/go-multierror)\n\n[circleci]: https://app.circleci.com/pipelines/github/hashicorp/go-multierror\n[godocs]: https://pkg.go.dev/github.com/hashicorp/go-multierror\n\n`go-multierror` is a package for Go that provides a mechanism for\nrepresenting a list of `error` values as a single `error`.\n\nThis allows a function in Go to return an `error` that might actually\nbe a list of errors. If the caller knows this, they can unwrap the\nlist and access the errors. If the caller doesn't know, the error\nformats to a nice human-readable format.\n\n`go-multierror` is fully compatible with the Go standard library\n[errors](https://golang.org/pkg/errors/) package, including the\nfunctions `As`, `Is`, and `Unwrap`. This provides a standardized approach\nfor introspecting on error values.\n\n## Installation and Docs\n\nInstall using `go get github.com/hashicorp/go-multierror`.\n\nFull documentation is available at\nhttps://pkg.go.dev/github.com/hashicorp/go-multierror\n\n### Requires go version 1.13 or newer\n\n`go-multierror` requires go version 1.13 or newer. Go 1.13 introduced\n[error wrapping](https://golang.org/doc/go1.13#error_wrapping), which\nthis library takes advantage of.\n\nIf you need to use an earlier version of go, you can use the\n[v1.0.0](https://github.com/hashicorp/go-multierror/tree/v1.0.0)\ntag, which doesn't rely on features in go 1.13.\n\nIf you see compile errors that look like the below, it's likely that\nyou're on an older version of go:\n\n```\n/go/src/github.com/hashicorp/go-multierror/multierror.go:112:9: undefined: errors.As\n/go/src/github.com/hashicorp/go-multierror/multierror.go:117:9: undefined: errors.Is\n```\n\n## Usage\n\ngo-multierror is easy to use and purposely built to be unobtrusive in\nexisting Go applications/libraries that may not be aware of it.\n\n**Building a list of errors**\n\nThe `Append` function is used to create a list of errors. This function\nbehaves a lot like the Go built-in `append` function: it doesn't matter\nif the first argument is nil, a `multierror.Error`, or any other `error`,\nthe function behaves as you would expect.\n\n```go\nvar result error\n\nif err := step1(); err != nil {\n\tresult = multierror.Append(result, err)\n}\nif err := step2(); err != nil {\n\tresult = multierror.Append(result, err)\n}\n\nreturn result\n```\n\n**Customizing the formatting of the errors**\n\nBy specifying a custom `ErrorFormat`, you can customize the format\nof the `Error() string` function:\n\n```go\nvar result *multierror.Error\n\n// ... accumulate errors here, maybe using Append\n\nif result != nil {\n\tresult.ErrorFormat = func([]error) string {\n\t\treturn \"errors!\"\n\t}\n}\n```\n\n**Accessing the list of errors**\n\n`multierror.Error` implements `error` so if the caller doesn't know about\nmultierror, it will work just fine. But if you're aware a multierror might\nbe returned, you can use type switches to access the list of errors:\n\n```go\nif err := something(); err != nil {\n\tif merr, ok := err.(*multierror.Error); ok {\n\t\t// Use merr.Errors\n\t}\n}\n```\n\nYou can also use the standard [`errors.Unwrap`](https://golang.org/pkg/errors/#Unwrap)\nfunction. This will continue to unwrap into subsequent errors until none exist.\n\n**Extracting an error**\n\nThe standard library [`errors.As`](https://golang.org/pkg/errors/#As)\nfunction can be used directly with a multierror to extract a specific error:\n\n```go\n// Assume err is a multierror value\nerr := somefunc()\n\n// We want to know if \"err\" has a \"RichErrorType\" in it and extract it.\nvar errRich RichErrorType\nif errors.As(err, \u0026errRich) {\n\t// It has it, and now errRich is populated.\n}\n```\n\n**Checking for an exact error value**\n\nSome errors are returned as exact errors such as the [`ErrNotExist`](https://golang.org/pkg/os/#pkg-variables)\nerror in the `os` package. You can check if this error is present by using\nthe standard [`errors.Is`](https://golang.org/pkg/errors/#Is) function.\n\n```go\n// Assume err is a multierror value\nerr := somefunc()\nif errors.Is(err, os.ErrNotExist) {\n\t// err contains os.ErrNotExist\n}\n```\n\n**Returning a multierror only if there are errors**\n\nIf you build a `multierror.Error`, you can use the `ErrorOrNil` function\nto return an `error` implementation only if there are errors to return:\n\n```go\nvar result *multierror.Error\n\n// ... accumulate errors here\n\n// Return the `error` only if errors were added to the multierror, otherwise\n// return nil since there are no errors.\nreturn result.ErrorOrNil()\n```\n","funding_links":[],"categories":["开源类库","Error Handling","\u003cspan id=\"其他-miscellaneous\"\u003e其他 Miscellaneous\u003c/span\u003e","Open source library","Miscellaneous","Go","错误处理`go 语言错误处理库`","错误处理","其他","Relational Databases","杂项"],"sub_categories":["错误处理","Search and Analytic Databases","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","Error Handling","Advanced Console UIs","SQL 查询语句构建库","检索及分析资料库","交流"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhashicorp%2Fgo-multierror","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhashicorp%2Fgo-multierror","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhashicorp%2Fgo-multierror/lists"}