-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from secureworks/phughes-std-multi-error
Rewrite MultiError logic to mirror decisions made in standard library
- Loading branch information
Showing
18 changed files
with
972 additions
and
574 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: Go | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
|
||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Set up Go 1.20 | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ^1.20 | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v2 | ||
|
||
- name: Get dependencies | ||
run: go mod download | ||
|
||
- name: Build | ||
run: go build -v ./... | ||
|
||
- name: Test | ||
run: go test -v ./... | ||
|
||
lint: | ||
name: Lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v2 | ||
|
||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v2 | ||
with: | ||
version: v1.42.0 | ||
config: .golangci.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
# Errors | ||
|
||
This package provides a suite of tools meant to work with Go 1.13 error | ||
wrapping to give users all the basics to handle errors in a useful way. | ||
wrapping and Go 1.20 multierrors. These helpers allow users to rely on | ||
standard Go error patterns while they include some "missing pieces" or | ||
additional features that are useful in practice. | ||
|
||
> _Another errors package? Why does Go need all of these error libraries?_ | ||
Because the language and the standard library have a minimal approach to error | ||
handling that leaves out some primitives power users expect to have on | ||
hand. | ||
hand. | ||
|
||
Important among these primitives are stack traces, error collections | ||
(multi-errors and error groups) and error types. While Go 1.13 introduced | ||
error wrapping utilities that have fixed some immediate issues, it is really | ||
useful to have a few more tools on hand. | ||
Important among these primitives are stack traces, explicit error collection | ||
types (multierrors and error groups) and error context management. | ||
|
||
While Go 1.13 introduced error wrapping utilities and Go 1.20 added a minimal | ||
multierror collection, it is really useful to have a few more tools on hand. | ||
|
||
### Installation | ||
|
||
> _This package **may not be used** in environments:_ | ||
> | ||
> 1. _running Go 1.12 or lower;_ | ||
> 1. _running Go 1.19 or lower;_ | ||
> 2. _running on 32-bit architecture;_ | ||
> 3. _running on Windows (**currently** not supported)._ | ||
Given that we are running on Go 1.13, your project should be using Go modules. | ||
Add the following to your file: | ||
|
||
```go | ||
|
@@ -32,9 +34,21 @@ import "github.com/secureworks/errors" | |
Then, when you run any Go command the toolchain will resolve and fetch the | ||
required modules automatically. | ||
|
||
> If you are using Go 1.13 to Go 1.19, you should use the previous version of | ||
> this library, which has the same functionality but does not support the | ||
> specific form that Go 1.20 multierrors take: | ||
> | ||
> ``` | ||
> $ go get github.com/secureworks/[email protected] | ||
> ``` | ||
Because this package re-exports the package-level functions of the standard | ||
library `"errors"` package, you do not need to include that package as well to | ||
get `New`, `As`, `Is`, or `Unwrap`. | ||
get `New`, `As`, `Is`, `Unwrap`, and `Join`. | ||
Note that `Join` is a special case: for consistency, and since our multierror is | ||
a better implementation, `Join` returns our implementation (which uses our | ||
formatting), not the standard library's implementation. | ||
### Use | ||
|
@@ -48,8 +62,8 @@ Package `github.com/secureworks/errors`: | |
- use in place of the standard library with no change in behavior; | ||
- use the `errors.MultiError` type as either an explicit multierror | ||
implementation or as an implicit multierror passed around with the default | ||
`error` interface; use `errors.Append` and others to simplify multierror | ||
management in your code; | ||
`error` interface; use `errors.Join`, `errors.Append` and others to simplify | ||
multierror management in your code; | ||
- embed (singular) stack frames with `errors.NewWithFrame("...")`, | ||
`errors.WithFrame(err)`, and `fmt.Errorf("...: %w", err)`; | ||
- embed stack traces with `errors.NewWithStackTrace("...")` and | ||
|
@@ -71,8 +85,6 @@ Package `github.com/secureworks/errors/syncerr`: | |
Possible improvements before reaching `v1.0` include: | ||
- **Add support for Windows filepaths in call frames.** | ||
- Add direct integrations with other errors packages (especially those listed | ||
in the codebase). | ||
- Include either a linter or a suggested [`golang-ci`][golang-ci] lint YAML | ||
to support idiomatic use. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.