Skip to content

Commit 0a50d64

Browse files
author
Dean Karn
authored
Add Join function (#23)
1 parent 24132cb commit 0a50d64

File tree

6 files changed

+71
-20
lines changed

6 files changed

+71
-20
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [5.4.0] - 2023-10-18
10+
### Added
11+
- Join function to join multiple errors into a single error to continue to be a drop-in replacement to the std library.
12+
913
## [5.3.3] - 2023-08-16
1014
### Fixed
1115
- First error inconsistently wrapped with error and prefix instead of err then prefix in the chain.
@@ -46,7 +50,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4650
- Updated deps.
4751

4852

49-
[Unreleased]: https://github.com/go-playground/errors/compare/v5.3.3...HEAD
53+
[Unreleased]: https://github.com/go-playground/errors/compare/v5.4.0...HEAD
54+
[5.4.0]: https://github.com/go-playground/errors/compare/v5.3.3...v5.4.0
5055
[5.3.3]: https://github.com/go-playground/errors/compare/v5.3.2...v5.3.3
5156
[5.3.2]: https://github.com/go-playground/errors/compare/v5.3.1...v5.3.2
5257
[5.3.1]: https://github.com/go-playground/errors/compare/v5.3.0...v5.3.1

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package errors
22
============
3-
![Project status](https://img.shields.io/badge/version-5.3.3-green.svg)
3+
![Project status](https://img.shields.io/badge/version-5.4.0-green.svg)
44
[![Build Status](https://travis-ci.org/go-playground/errors.svg?branch=master)](https://travis-ci.org/go-playground/errors)
55
[![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/errors)](https://goreportcard.com/report/github.com/go-playground/errors)
66
[![GoDoc](https://godoc.org/github.com/go-playground/errors?status.svg)](https://pkg.go.dev/github.com/go-playground/errors/v5)

errors_go1.20.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//go:build go1.20
2+
// +build go1.20
3+
4+
package errors
5+
6+
import stderrors "errors"
7+
8+
// Join allows this library to be a drop-in replacement to the std library.
9+
//
10+
// Join returns an error that wraps the given errors. Any nil error values are discarded.
11+
// Join returns nil if every value in errs is nil. The error formats as the concatenation of the strings obtained
12+
// by calling the Error method of each element of errs, with a newline between each string.
13+
//
14+
// A non-nil error returned by Join implements the Unwrap() []error method.
15+
//
16+
// It is the responsibility of the caller to then check for nil and wrap this error if desired.
17+
func Join(errs ...error) error {
18+
return stderrors.Join(errs...)
19+
}

errors_go1.20_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//go:build go1.20
2+
// +build go1.20
3+
4+
package errors
5+
6+
import (
7+
"io"
8+
"testing"
9+
)
10+
11+
func TestJoin(t *testing.T) {
12+
err1 := io.EOF
13+
err2 := io.ErrUnexpectedEOF
14+
15+
err := Join(err1, err2)
16+
innerErr, ok := err.(interface{ Unwrap() []error })
17+
if !ok {
18+
t.Fatalf("expected Join to return an error that implements Unwrap() []error")
19+
}
20+
errs := innerErr.Unwrap()
21+
if len(errs) != 2 {
22+
t.Fatalf("expected Join to return an error that implements Unwrap() []error to return 2 errors")
23+
}
24+
if !Is(errs[0], io.EOF) {
25+
t.Fatalf("expected Join to return an error that implements Unwrap() []error to return io.EOF")
26+
}
27+
if !Is(errs[1], io.ErrUnexpectedEOF) {
28+
t.Fatalf("expected Join to return an error that implements Unwrap() []error to return io.ErrUnexpectedEOF")
29+
}
30+
31+
// test wrapping and then unwrapping with Chain
32+
err = Wrap(err, "my test wrapped error")
33+
if !Is(err, io.EOF) {
34+
t.Fatalf("expected wrapped error to traverse into joined inner error EOF")
35+
}
36+
if !Is(err, io.ErrUnexpectedEOF) {
37+
t.Fatalf("expected wrapped error to traverse into joined inner error ErrUnexpectedEOF")
38+
}
39+
}

go.mod

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ module github.com/go-playground/errors/v5
33
go 1.18
44

55
require (
6-
github.com/aws/aws-sdk-go v1.44.244
7-
github.com/go-playground/pkg/v5 v5.15.2
6+
github.com/aws/aws-sdk-go v1.45.27
7+
github.com/go-playground/pkg/v5 v5.21.3
88
)
9-
10-
require github.com/jmespath/go-jmespath v0.4.0 // indirect

go.sum

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
github.com/aws/aws-sdk-go v1.44.24 h1:3nOkwJBJLiGBmJKWp3z0utyXuBkxyGkRRwWjrTItJaY=
2-
github.com/aws/aws-sdk-go v1.44.24/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=
3-
github.com/aws/aws-sdk-go v1.44.244 h1:QzBWLD5HjZHdRZyTMTOWtD9Pobzf1n8/CeTJB4giXi0=
4-
github.com/aws/aws-sdk-go v1.44.244/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
1+
github.com/aws/aws-sdk-go v1.45.27 h1:b+zOTPkAG4i2RvqPdHxkJZafmhhVaVHBp4r41Tu4I6U=
2+
github.com/aws/aws-sdk-go v1.45.27/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
53
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6-
github.com/go-playground/assert v1.2.1/go.mod h1:Lgy+k19nOB/wQG/fVSQ7rra5qYugmytMQqvQ2dgjWn8=
7-
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
8-
github.com/go-playground/form/v4 v4.1.1/go.mod h1:q1a2BY+AQUUzhl6xA/6hBetay6dEIhMHjgvJiGo6K7U=
9-
github.com/go-playground/pkg/v5 v5.0.0 h1:cml7lI472g05ANLG0Or2B6dyeFrnkQazTDEWdJx9/x4=
10-
github.com/go-playground/pkg/v5 v5.0.0/go.mod h1:0380E0lsFB1POWFypOLL8tX2f0O1OBCBpSdVmEy4mg0=
11-
github.com/go-playground/pkg/v5 v5.15.2 h1:/PSAD9FTPd+pZ6dn22tCiKJGGCEbZMRXqkC/5bwvVBw=
12-
github.com/go-playground/pkg/v5 v5.15.2/go.mod h1:eT8XZeFHnqZkfkpkbI8ayjfCw9GohV2/j8STbVmoR6s=
13-
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
4+
github.com/go-playground/pkg/v5 v5.21.3 h1:1IVy0eupI5kht6L6zaAqTEvjs00zLkG28ictNkoN1wE=
5+
github.com/go-playground/pkg/v5 v5.21.3/go.mod h1:UgHNntEQnMJSygw2O2RQ3LAB0tprx81K90c/pOKh7cU=
146
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
157
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
168
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -22,15 +14,13 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
2214
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
2315
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
2416
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
25-
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
2617
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
2718
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
2819
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
2920
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
3021
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
3122
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
3223
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
33-
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3424
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3525
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3626
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

0 commit comments

Comments
 (0)