Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Join function #23

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [5.4.0] - 2023-10-18
### Added
- Join function to join multiple errors into a single error to continue to be a drop-in replacement to the std library.

## [5.3.3] - 2023-08-16
### Fixed
- First error inconsistently wrapped with error and prefix instead of err then prefix in the chain.
Expand Down Expand Up @@ -46,7 +50,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Updated deps.


[Unreleased]: https://github.com/go-playground/errors/compare/v5.3.3...HEAD
[Unreleased]: https://github.com/go-playground/errors/compare/v5.4.0...HEAD
[5.4.0]: https://github.com/go-playground/errors/compare/v5.3.3...v5.4.0
[5.3.3]: https://github.com/go-playground/errors/compare/v5.3.2...v5.3.3
[5.3.2]: https://github.com/go-playground/errors/compare/v5.3.1...v5.3.2
[5.3.1]: https://github.com/go-playground/errors/compare/v5.3.0...v5.3.1
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package errors
============
![Project status](https://img.shields.io/badge/version-5.3.3-green.svg)
![Project status](https://img.shields.io/badge/version-5.4.0-green.svg)
[![Build Status](https://travis-ci.org/go-playground/errors.svg?branch=master)](https://travis-ci.org/go-playground/errors)
[![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/errors)](https://goreportcard.com/report/github.com/go-playground/errors)
[![GoDoc](https://godoc.org/github.com/go-playground/errors?status.svg)](https://pkg.go.dev/github.com/go-playground/errors/v5)
Expand Down
19 changes: 19 additions & 0 deletions errors_go1.20.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//go:build go1.20
// +build go1.20

package errors

import stderrors "errors"

// Join allows this library to be a drop-in replacement to the std library.
//
// Join returns an error that wraps the given errors. Any nil error values are discarded.
// Join returns nil if every value in errs is nil. The error formats as the concatenation of the strings obtained
// by calling the Error method of each element of errs, with a newline between each string.
//
// A non-nil error returned by Join implements the Unwrap() []error method.
//
// It is the responsibility of the caller to then check for nil and wrap this error if desired.
func Join(errs ...error) error {
return stderrors.Join(errs...)
}
39 changes: 39 additions & 0 deletions errors_go1.20_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//go:build go1.20
// +build go1.20

package errors

import (
"io"
"testing"
)

func TestJoin(t *testing.T) {
err1 := io.EOF
err2 := io.ErrUnexpectedEOF

err := Join(err1, err2)
innerErr, ok := err.(interface{ Unwrap() []error })
if !ok {
t.Fatalf("expected Join to return an error that implements Unwrap() []error")
}
errs := innerErr.Unwrap()
if len(errs) != 2 {
t.Fatalf("expected Join to return an error that implements Unwrap() []error to return 2 errors")
}
if !Is(errs[0], io.EOF) {
t.Fatalf("expected Join to return an error that implements Unwrap() []error to return io.EOF")
}
if !Is(errs[1], io.ErrUnexpectedEOF) {
t.Fatalf("expected Join to return an error that implements Unwrap() []error to return io.ErrUnexpectedEOF")
}

// test wrapping and then unwrapping with Chain
err = Wrap(err, "my test wrapped error")
if !Is(err, io.EOF) {
t.Fatalf("expected wrapped error to traverse into joined inner error EOF")
}
if !Is(err, io.ErrUnexpectedEOF) {
t.Fatalf("expected wrapped error to traverse into joined inner error ErrUnexpectedEOF")
}
}
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ module github.com/go-playground/errors/v5
go 1.18

require (
github.com/aws/aws-sdk-go v1.44.244
github.com/go-playground/pkg/v5 v5.15.2
github.com/aws/aws-sdk-go v1.45.27
github.com/go-playground/pkg/v5 v5.21.3
)

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