From fa33db175b60e9fce79ec6387eea0fdd7631dbcf Mon Sep 17 00:00:00 2001 From: Michael Spiegel Date: Wed, 10 Aug 2016 21:43:25 -0400 Subject: [PATCH 01/12] Preserve nil value when no errors have occurred. This patch handles nil values when passed into the slice argument of AppendNonNil(err error, errs ...error). nil values are filtered out and not included in the multierror. When the first argument to AppendNonNil is nil, and the second argument consists entirely of nil values, then return a nil value. This patch allows the usage the following style. ``` var result error result = multierror.AppendNonNil(result, step1()) result = multierror.AppendNonNil(result, step2()) return result ``` result will be nil if-and-only-if step1() and step2() both return nil. --- append.go | 33 +++++++++++++++++++++++++++++++++ append_test.go | 16 ++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/append.go b/append.go index 00afa9b..2a20dbe 100644 --- a/append.go +++ b/append.go @@ -1,5 +1,38 @@ package multierror +// removeNils preserves the non-nil elements +// of a slice. This is a destructive operation +// the contents of the original slice are modified. +func removeNils(errs []error) []error { + view := errs[:0] + for _, err := range errs { + if err != nil { + view = append(view, err) + } + } + return view +} + +// AppendNonNil is a helper function that will append more errors +// onto an Error in order to create a larger multi-error. +// +// If err is not a multierror.Error, then it will be turned into +// one. If any of the errs are multierr.Error, they will be flattened +// one level into err. +// +// nil values in errs are filtered out. If the err is nil and +// the length of filtered errs is zero then the function returns nil. +func AppendNonNil(err error, errs ...error) *Error { + + errs = removeNils(errs) + // Preserve nil value when no errors have occurred + if err == nil && len(errs) == 0 { + return nil + } + + return Append(err, errs...) +} + // Append is a helper function that will append more errors // onto an Error in order to create a larger multi-error. // diff --git a/append_test.go b/append_test.go index dfa79e2..448ed34 100644 --- a/append_test.go +++ b/append_test.go @@ -5,6 +5,14 @@ import ( "testing" ) +func TestRemoveNils(t *testing.T) { + errs := []error{errors.New("foo"), nil, nil, errors.New("foo"), nil} + errs = removeNils(errs) + if len(errs) != 2 { + t.Fatalf("wrong len: %d", len(errs)) + } +} + func TestAppend_Error(t *testing.T) { original := &Error{ Errors: []error{errors.New("foo")}, @@ -47,6 +55,14 @@ func TestAppend_NilError(t *testing.T) { } } +func TestAppend_NilNil(t *testing.T) { + var err error + result := AppendNonNil(err, nil) + if result != nil { + t.Fatalf("non-nil errors: %s", result.GoString()) + } +} + func TestAppend_NonError(t *testing.T) { original := errors.New("foo") result := Append(original, errors.New("bar")) From 1e17297b2b2e290e4a293200ccc6ed11261bb558 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Wed, 10 Aug 2016 21:51:04 -0400 Subject: [PATCH 02/12] Add travis stuff --- .travis.yml | 12 ++++++++++++ Makefile | 31 +++++++++++++++++++++++++++++++ README.md | 6 ++++++ 3 files changed, 49 insertions(+) create mode 100644 .travis.yml create mode 100644 Makefile diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..4b865d1 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +sudo: false + +language: go + +go: + - 1.6 + +branches: + only: + - master + +script: make test testrace diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b97cd6e --- /dev/null +++ b/Makefile @@ -0,0 +1,31 @@ +TEST?=./... + +default: test + +# test runs the test suite and vets the code. +test: generate + @echo "==> Running tests..." + @go list $(TEST) \ + | grep -v "/vendor/" \ + | xargs -n1 go test -timeout=60s -parallel=10 ${TESTARGS} + +# testrace runs the race checker +testrace: generate + @echo "==> Running tests (race)..." + @go list $(TEST) \ + | grep -v "/vendor/" \ + | xargs -n1 go test -timeout=60s -race ${TESTARGS} + +# updatedeps installs all the dependencies needed to run and build. +updatedeps: + @sh -c "'${CURDIR}/scripts/deps.sh' '${NAME}'" + +# generate runs `go generate` to build the dynamically generated source files. +generate: + @echo "==> Generating..." + @find . -type f -name '.DS_Store' -delete + @go list ./... \ + | grep -v "/vendor/" \ + | xargs -n1 go generate + +.PHONY: default test testrace updatedeps generate diff --git a/README.md b/README.md index e81be50..ead5830 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ # go-multierror +[![Build Status](http://img.shields.io/travis/hashicorp/go-multierror.svg?style=flat-square)][travis] +[![Go Documentation](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)][godocs] + +[travis]: https://travis-ci.org/hashicorp/go-multierror +[godocs]: https://godoc.org/github.com/hashicorp/go-multierror + `go-multierror` is a package for Go that provides a mechanism for representing a list of `error` values as a single `error`. From 35878e7e5065e576772e7532bb10e5e0f478d330 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Wed, 10 Aug 2016 21:57:21 -0400 Subject: [PATCH 03/12] Add deps script --- scripts/deps.sh | 54 +++ vendor/github.com/hashicorp/errwrap/LICENSE | 354 ++++++++++++++++++ vendor/github.com/hashicorp/errwrap/README.md | 89 +++++ .../github.com/hashicorp/errwrap/errwrap.go | 169 +++++++++ vendor/vendor.json | 13 + 5 files changed, 679 insertions(+) create mode 100755 scripts/deps.sh create mode 100644 vendor/github.com/hashicorp/errwrap/LICENSE create mode 100644 vendor/github.com/hashicorp/errwrap/README.md create mode 100644 vendor/github.com/hashicorp/errwrap/errwrap.go create mode 100644 vendor/vendor.json diff --git a/scripts/deps.sh b/scripts/deps.sh new file mode 100755 index 0000000..1d2fcf9 --- /dev/null +++ b/scripts/deps.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +# +# This script updates dependencies using a temporary directory. This is required +# to avoid any auxillary dependencies that sneak into GOPATH. +set -e + +# Get the parent directory of where this script is. +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done +DIR="$(cd -P "$(dirname "$SOURCE")/.." && pwd)" + +# Change into that directory +cd "$DIR" + +# Get the name from the directory +NAME=${NAME:-"$(basename $(pwd))"} + +# Announce +echo "==> Updating dependencies..." + +echo "--> Making tmpdir..." +tmpdir=$(mktemp -d) +function cleanup { + rm -rf "${tmpdir}" +} +trap cleanup EXIT + +export GOPATH="${tmpdir}" +export PATH="${tmpdir}/bin:$PATH" + +mkdir -p "${tmpdir}/src/github.com/hashicorp" +pushd "${tmpdir}/src/github.com/hashicorp" &>/dev/null + +echo "--> Copying ${NAME}..." +cp -R "$DIR" "${tmpdir}/src/github.com/hashicorp/${NAME}" +pushd "${tmpdir}/src/github.com/hashicorp/${NAME}" &>/dev/null +rm -rf vendor/ + +echo "--> Installing dependency manager..." +go get -u github.com/kardianos/govendor +govendor init + +echo "--> Installing all dependencies (may take some time)..." +govendor fetch -v +outside + +echo "--> Vendoring..." +govendor add +external + +echo "--> Moving into place..." +vpath="${tmpdir}/src/github.com/hashicorp/${NAME}/vendor" +popd &>/dev/null +popd &>/dev/null +rm -rf vendor/ +cp -R "${vpath}" . diff --git a/vendor/github.com/hashicorp/errwrap/LICENSE b/vendor/github.com/hashicorp/errwrap/LICENSE new file mode 100644 index 0000000..c33dcc7 --- /dev/null +++ b/vendor/github.com/hashicorp/errwrap/LICENSE @@ -0,0 +1,354 @@ +Mozilla Public License, version 2.0 + +1. Definitions + +1.1. “Contributor” + + means each individual or legal entity that creates, contributes to the + creation of, or owns Covered Software. + +1.2. “Contributor Version” + + means the combination of the Contributions of others (if any) used by a + Contributor and that particular Contributor’s Contribution. + +1.3. “Contribution” + + means Covered Software of a particular Contributor. + +1.4. “Covered Software” + + means Source Code Form to which the initial Contributor has attached the + notice in Exhibit A, the Executable Form of such Source Code Form, and + Modifications of such Source Code Form, in each case including portions + thereof. + +1.5. “Incompatible With Secondary Licenses” + means + + a. that the initial Contributor has attached the notice described in + Exhibit B to the Covered Software; or + + b. that the Covered Software was made available under the terms of version + 1.1 or earlier of the License, but not also under the terms of a + Secondary License. + +1.6. “Executable Form” + + means any form of the work other than Source Code Form. + +1.7. “Larger Work” + + means a work that combines Covered Software with other material, in a separate + file or files, that is not Covered Software. + +1.8. “License” + + means this document. + +1.9. “Licensable” + + means having the right to grant, to the maximum extent possible, whether at the + time of the initial grant or subsequently, any and all of the rights conveyed by + this License. + +1.10. “Modifications” + + means any of the following: + + a. any file in Source Code Form that results from an addition to, deletion + from, or modification of the contents of Covered Software; or + + b. any new file in Source Code Form that contains any Covered Software. + +1.11. “Patent Claims” of a Contributor + + means any patent claim(s), including without limitation, method, process, + and apparatus claims, in any patent Licensable by such Contributor that + would be infringed, but for the grant of the License, by the making, + using, selling, offering for sale, having made, import, or transfer of + either its Contributions or its Contributor Version. + +1.12. “Secondary License” + + means either the GNU General Public License, Version 2.0, the GNU Lesser + General Public License, Version 2.1, the GNU Affero General Public + License, Version 3.0, or any later versions of those licenses. + +1.13. “Source Code Form” + + means the form of the work preferred for making modifications. + +1.14. “You” (or “Your”) + + means an individual or a legal entity exercising rights under this + License. For legal entities, “You” includes any entity that controls, is + controlled by, or is under common control with You. For purposes of this + definition, “control” means (a) the power, direct or indirect, to cause + the direction or management of such entity, whether by contract or + otherwise, or (b) ownership of more than fifty percent (50%) of the + outstanding shares or beneficial ownership of such entity. + + +2. License Grants and Conditions + +2.1. Grants + + Each Contributor hereby grants You a world-wide, royalty-free, + non-exclusive license: + + a. under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or as + part of a Larger Work; and + + b. under Patent Claims of such Contributor to make, use, sell, offer for + sale, have made, import, and otherwise transfer either its Contributions + or its Contributor Version. + +2.2. Effective Date + + The licenses granted in Section 2.1 with respect to any Contribution become + effective for each Contribution on the date the Contributor first distributes + such Contribution. + +2.3. Limitations on Grant Scope + + The licenses granted in this Section 2 are the only rights granted under this + License. No additional rights or licenses will be implied from the distribution + or licensing of Covered Software under this License. Notwithstanding Section + 2.1(b) above, no patent license is granted by a Contributor: + + a. for any code that a Contributor has removed from Covered Software; or + + b. for infringements caused by: (i) Your and any other third party’s + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + + c. under Patent Claims infringed by Covered Software in the absence of its + Contributions. + + This License does not grant any rights in the trademarks, service marks, or + logos of any Contributor (except as may be necessary to comply with the + notice requirements in Section 3.4). + +2.4. Subsequent Licenses + + No Contributor makes additional grants as a result of Your choice to + distribute the Covered Software under a subsequent version of this License + (see Section 10.2) or under the terms of a Secondary License (if permitted + under the terms of Section 3.3). + +2.5. Representation + + Each Contributor represents that the Contributor believes its Contributions + are its original creation(s) or it has sufficient rights to grant the + rights to its Contributions conveyed by this License. + +2.6. Fair Use + + This License is not intended to limit any rights You have under applicable + copyright doctrines of fair use, fair dealing, or other equivalents. + +2.7. Conditions + + Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in + Section 2.1. + + +3. Responsibilities + +3.1. Distribution of Source Form + + All distribution of Covered Software in Source Code Form, including any + Modifications that You create or to which You contribute, must be under the + terms of this License. You must inform recipients that the Source Code Form + of the Covered Software is governed by the terms of this License, and how + they can obtain a copy of this License. You may not attempt to alter or + restrict the recipients’ rights in the Source Code Form. + +3.2. Distribution of Executable Form + + If You distribute Covered Software in Executable Form then: + + a. such Covered Software must also be made available in Source Code Form, + as described in Section 3.1, and You must inform recipients of the + Executable Form how they can obtain a copy of such Source Code Form by + reasonable means in a timely manner, at a charge no more than the cost + of distribution to the recipient; and + + b. You may distribute such Executable Form under the terms of this License, + or sublicense it under different terms, provided that the license for + the Executable Form does not attempt to limit or alter the recipients’ + rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + + You may create and distribute a Larger Work under terms of Your choice, + provided that You also comply with the requirements of this License for the + Covered Software. If the Larger Work is a combination of Covered Software + with a work governed by one or more Secondary Licenses, and the Covered + Software is not Incompatible With Secondary Licenses, this License permits + You to additionally distribute such Covered Software under the terms of + such Secondary License(s), so that the recipient of the Larger Work may, at + their option, further distribute the Covered Software under the terms of + either this License or such Secondary License(s). + +3.4. Notices + + You may not remove or alter the substance of any license notices (including + copyright notices, patent notices, disclaimers of warranty, or limitations + of liability) contained within the Source Code Form of the Covered + Software, except that You may alter any license notices to the extent + required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + + You may choose to offer, and to charge a fee for, warranty, support, + indemnity or liability obligations to one or more recipients of Covered + Software. However, You may do so only on Your own behalf, and not on behalf + of any Contributor. You must make it absolutely clear that any such + warranty, support, indemnity, or liability obligation is offered by You + alone, and You hereby agree to indemnify every Contributor for any + liability incurred by such Contributor as a result of warranty, support, + indemnity or liability terms You offer. You may include additional + disclaimers of warranty and limitations of liability specific to any + jurisdiction. + +4. Inability to Comply Due to Statute or Regulation + + If it is impossible for You to comply with any of the terms of this License + with respect to some or all of the Covered Software due to statute, judicial + order, or regulation then You must: (a) comply with the terms of this License + to the maximum extent possible; and (b) describe the limitations and the code + they affect. Such description must be placed in a text file included with all + distributions of the Covered Software under this License. Except to the + extent prohibited by statute or regulation, such description must be + sufficiently detailed for a recipient of ordinary skill to be able to + understand it. + +5. Termination + +5.1. The rights granted under this License will terminate automatically if You + fail to comply with any of its terms. However, if You become compliant, + then the rights granted under this License from a particular Contributor + are reinstated (a) provisionally, unless and until such Contributor + explicitly and finally terminates Your grants, and (b) on an ongoing basis, + if such Contributor fails to notify You of the non-compliance by some + reasonable means prior to 60 days after You have come back into compliance. + Moreover, Your grants from a particular Contributor are reinstated on an + ongoing basis if such Contributor notifies You of the non-compliance by + some reasonable means, this is the first time You have received notice of + non-compliance with this License from such Contributor, and You become + compliant prior to 30 days after Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent + infringement claim (excluding declaratory judgment actions, counter-claims, + and cross-claims) alleging that a Contributor Version directly or + indirectly infringes any patent, then the rights granted to You by any and + all Contributors for the Covered Software under Section 2.1 of this License + shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user + license agreements (excluding distributors and resellers) which have been + validly granted by You or Your distributors under this License prior to + termination shall survive termination. + +6. Disclaimer of Warranty + + Covered Software is provided under this License on an “as is” basis, without + warranty of any kind, either expressed, implied, or statutory, including, + without limitation, warranties that the Covered Software is free of defects, + merchantable, fit for a particular purpose or non-infringing. The entire + risk as to the quality and performance of the Covered Software is with You. + Should any Covered Software prove defective in any respect, You (not any + Contributor) assume the cost of any necessary servicing, repair, or + correction. This disclaimer of warranty constitutes an essential part of this + License. No use of any Covered Software is authorized under this License + except under this disclaimer. + +7. Limitation of Liability + + Under no circumstances and under no legal theory, whether tort (including + negligence), contract, or otherwise, shall any Contributor, or anyone who + distributes Covered Software as permitted above, be liable to You for any + direct, indirect, special, incidental, or consequential damages of any + character including, without limitation, damages for lost profits, loss of + goodwill, work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses, even if such party shall have been + informed of the possibility of such damages. This limitation of liability + shall not apply to liability for death or personal injury resulting from such + party’s negligence to the extent applicable law prohibits such limitation. + Some jurisdictions do not allow the exclusion or limitation of incidental or + consequential damages, so this exclusion and limitation may not apply to You. + +8. Litigation + + Any litigation relating to this License may be brought only in the courts of + a jurisdiction where the defendant maintains its principal place of business + and such litigation shall be governed by laws of that jurisdiction, without + reference to its conflict-of-law provisions. Nothing in this Section shall + prevent a party’s ability to bring cross-claims or counter-claims. + +9. Miscellaneous + + This License represents the complete agreement concerning the subject matter + hereof. If any provision of this License is held to be unenforceable, such + provision shall be reformed only to the extent necessary to make it + enforceable. Any law or regulation which provides that the language of a + contract shall be construed against the drafter shall not be used to construe + this License against a Contributor. + + +10. Versions of the License + +10.1. New Versions + + Mozilla Foundation is the license steward. Except as provided in Section + 10.3, no one other than the license steward has the right to modify or + publish new versions of this License. Each version will be given a + distinguishing version number. + +10.2. Effect of New Versions + + You may distribute the Covered Software under the terms of the version of + the License under which You originally received the Covered Software, or + under the terms of any subsequent version published by the license + steward. + +10.3. Modified Versions + + If you create software not governed by this License, and you want to + create a new license for such software, you may create and use a modified + version of this License if you rename the license and remove any + references to the name of the license steward (except to note that such + modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses + If You choose to distribute Source Code Form that is Incompatible With + Secondary Licenses under the terms of this version of the License, the + notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice + + This Source Code Form is subject to the + terms of the Mozilla Public License, v. + 2.0. If a copy of the MPL was not + distributed with this file, You can + obtain one at + http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular file, then +You may include the notice in a location (such as a LICENSE file in a relevant +directory) where a recipient would be likely to look for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - “Incompatible With Secondary Licenses” Notice + + This Source Code Form is “Incompatible + With Secondary Licenses”, as defined by + the Mozilla Public License, v. 2.0. + diff --git a/vendor/github.com/hashicorp/errwrap/README.md b/vendor/github.com/hashicorp/errwrap/README.md new file mode 100644 index 0000000..1c95f59 --- /dev/null +++ b/vendor/github.com/hashicorp/errwrap/README.md @@ -0,0 +1,89 @@ +# errwrap + +`errwrap` is a package for Go that formalizes the pattern of wrapping errors +and checking if an error contains another error. + +There is a common pattern in Go of taking a returned `error` value and +then wrapping it (such as with `fmt.Errorf`) before returning it. The problem +with this pattern is that you completely lose the original `error` structure. + +Arguably the _correct_ approach is that you should make a custom structure +implementing the `error` interface, and have the original error as a field +on that structure, such [as this example](http://golang.org/pkg/os/#PathError). +This is a good approach, but you have to know the entire chain of possible +rewrapping that happens, when you might just care about one. + +`errwrap` formalizes this pattern (it doesn't matter what approach you use +above) by giving a single interface for wrapping errors, checking if a specific +error is wrapped, and extracting that error. + +## Installation and Docs + +Install using `go get github.com/hashicorp/errwrap`. + +Full documentation is available at +http://godoc.org/github.com/hashicorp/errwrap + +## Usage + +#### Basic Usage + +Below is a very basic example of its usage: + +```go +// A function that always returns an error, but wraps it, like a real +// function might. +func tryOpen() error { + _, err := os.Open("/i/dont/exist") + if err != nil { + return errwrap.Wrapf("Doesn't exist: {{err}}", err) + } + + return nil +} + +func main() { + err := tryOpen() + + // We can use the Contains helpers to check if an error contains + // another error. It is safe to do this with a nil error, or with + // an error that doesn't even use the errwrap package. + if errwrap.Contains(err, ErrNotExist) { + // Do something + } + if errwrap.ContainsType(err, new(os.PathError)) { + // Do something + } + + // Or we can use the associated `Get` functions to just extract + // a specific error. This would return nil if that specific error doesn't + // exist. + perr := errwrap.GetType(err, new(os.PathError)) +} +``` + +#### Custom Types + +If you're already making custom types that properly wrap errors, then +you can get all the functionality of `errwraps.Contains` and such by +implementing the `Wrapper` interface with just one function. Example: + +```go +type AppError { + Code ErrorCode + Err error +} + +func (e *AppError) WrappedErrors() []error { + return []error{e.Err} +} +``` + +Now this works: + +```go +err := &AppError{Err: fmt.Errorf("an error")} +if errwrap.ContainsType(err, fmt.Errorf("")) { + // This will work! +} +``` diff --git a/vendor/github.com/hashicorp/errwrap/errwrap.go b/vendor/github.com/hashicorp/errwrap/errwrap.go new file mode 100644 index 0000000..a733bef --- /dev/null +++ b/vendor/github.com/hashicorp/errwrap/errwrap.go @@ -0,0 +1,169 @@ +// Package errwrap implements methods to formalize error wrapping in Go. +// +// All of the top-level functions that take an `error` are built to be able +// to take any error, not just wrapped errors. This allows you to use errwrap +// without having to type-check and type-cast everywhere. +package errwrap + +import ( + "errors" + "reflect" + "strings" +) + +// WalkFunc is the callback called for Walk. +type WalkFunc func(error) + +// Wrapper is an interface that can be implemented by custom types to +// have all the Contains, Get, etc. functions in errwrap work. +// +// When Walk reaches a Wrapper, it will call the callback for every +// wrapped error in addition to the wrapper itself. Since all the top-level +// functions in errwrap use Walk, this means that all those functions work +// with your custom type. +type Wrapper interface { + WrappedErrors() []error +} + +// Wrap defines that outer wraps inner, returning an error type that +// can be cleanly used with the other methods in this package, such as +// Contains, GetAll, etc. +// +// This function won't modify the error message at all (the outer message +// will be used). +func Wrap(outer, inner error) error { + return &wrappedError{ + Outer: outer, + Inner: inner, + } +} + +// Wrapf wraps an error with a formatting message. This is similar to using +// `fmt.Errorf` to wrap an error. If you're using `fmt.Errorf` to wrap +// errors, you should replace it with this. +// +// format is the format of the error message. The string '{{err}}' will +// be replaced with the original error message. +func Wrapf(format string, err error) error { + outerMsg := "" + if err != nil { + outerMsg = err.Error() + } + + outer := errors.New(strings.Replace( + format, "{{err}}", outerMsg, -1)) + + return Wrap(outer, err) +} + +// Contains checks if the given error contains an error with the +// message msg. If err is not a wrapped error, this will always return +// false unless the error itself happens to match this msg. +func Contains(err error, msg string) bool { + return len(GetAll(err, msg)) > 0 +} + +// ContainsType checks if the given error contains an error with +// the same concrete type as v. If err is not a wrapped error, this will +// check the err itself. +func ContainsType(err error, v interface{}) bool { + return len(GetAllType(err, v)) > 0 +} + +// Get is the same as GetAll but returns the deepest matching error. +func Get(err error, msg string) error { + es := GetAll(err, msg) + if len(es) > 0 { + return es[len(es)-1] + } + + return nil +} + +// GetType is the same as GetAllType but returns the deepest matching error. +func GetType(err error, v interface{}) error { + es := GetAllType(err, v) + if len(es) > 0 { + return es[len(es)-1] + } + + return nil +} + +// GetAll gets all the errors that might be wrapped in err with the +// given message. The order of the errors is such that the outermost +// matching error (the most recent wrap) is index zero, and so on. +func GetAll(err error, msg string) []error { + var result []error + + Walk(err, func(err error) { + if err.Error() == msg { + result = append(result, err) + } + }) + + return result +} + +// GetAllType gets all the errors that are the same type as v. +// +// The order of the return value is the same as described in GetAll. +func GetAllType(err error, v interface{}) []error { + var result []error + + var search string + if v != nil { + search = reflect.TypeOf(v).String() + } + Walk(err, func(err error) { + var needle string + if err != nil { + needle = reflect.TypeOf(err).String() + } + + if needle == search { + result = append(result, err) + } + }) + + return result +} + +// Walk walks all the wrapped errors in err and calls the callback. If +// err isn't a wrapped error, this will be called once for err. If err +// is a wrapped error, the callback will be called for both the wrapper +// that implements error as well as the wrapped error itself. +func Walk(err error, cb WalkFunc) { + if err == nil { + return + } + + switch e := err.(type) { + case *wrappedError: + cb(e.Outer) + Walk(e.Inner, cb) + case Wrapper: + cb(err) + + for _, err := range e.WrappedErrors() { + Walk(err, cb) + } + default: + cb(err) + } +} + +// wrappedError is an implementation of error that has both the +// outer and inner errors. +type wrappedError struct { + Outer error + Inner error +} + +func (w *wrappedError) Error() string { + return w.Outer.Error() +} + +func (w *wrappedError) WrappedErrors() []error { + return []error{w.Outer, w.Inner} +} diff --git a/vendor/vendor.json b/vendor/vendor.json new file mode 100644 index 0000000..56de487 --- /dev/null +++ b/vendor/vendor.json @@ -0,0 +1,13 @@ +{ + "comment": "", + "ignore": "test", + "package": [ + { + "checksumSHA1": "cdOCt0Yb+hdErz8NAQqayxPmRsY=", + "path": "github.com/hashicorp/errwrap", + "revision": "7554cd9344cec97297fa6649b055a8c98c2a1e55", + "revisionTime": "2014-10-28T05:47:10Z" + } + ], + "rootPath": "github.com/hashicorp/go-multierror" +} From a20743b1287aab5f982aa57ffd49aa7af5d45d8d Mon Sep 17 00:00:00 2001 From: Michael Spiegel Date: Wed, 10 Aug 2016 23:15:47 -0400 Subject: [PATCH 04/12] Bug fix for nil interface in appendNonNil() --- append.go | 6 +++++- append_test.go | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/append.go b/append.go index 2a20dbe..6dd02df 100644 --- a/append.go +++ b/append.go @@ -1,12 +1,16 @@ package multierror +import ( + "reflect" +) + // removeNils preserves the non-nil elements // of a slice. This is a destructive operation // the contents of the original slice are modified. func removeNils(errs []error) []error { view := errs[:0] for _, err := range errs { - if err != nil { + if err != nil && !reflect.ValueOf(err).IsNil() { view = append(view, err) } } diff --git a/append_test.go b/append_test.go index 448ed34..ca1465e 100644 --- a/append_test.go +++ b/append_test.go @@ -63,6 +63,15 @@ func TestAppend_NilNil(t *testing.T) { } } +func TestAppendNonNil(t *testing.T) { + var err1 error + var err2 *Error + result := AppendNonNil(err1, err2) + if result != nil { + t.Fatalf("non-nil errors: %s", result.GoString()) + } +} + func TestAppend_NonError(t *testing.T) { original := errors.New("foo") result := Append(original, errors.New("bar")) From c2714b7c159bd8ed98b7d20bbfdc9f74b92f4f63 Mon Sep 17 00:00:00 2001 From: Michael Spiegel Date: Wed, 10 Aug 2016 23:32:18 -0400 Subject: [PATCH 05/12] Another AppendNonNil interface bugfix. Do not convert 'nil' error to 'nil' *Error. --- append.go | 2 +- append_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/append.go b/append.go index 6dd02df..0f1b68c 100644 --- a/append.go +++ b/append.go @@ -26,7 +26,7 @@ func removeNils(errs []error) []error { // // nil values in errs are filtered out. If the err is nil and // the length of filtered errs is zero then the function returns nil. -func AppendNonNil(err error, errs ...error) *Error { +func AppendNonNil(err error, errs ...error) error { errs = removeNils(errs) // Preserve nil value when no errors have occurred diff --git a/append_test.go b/append_test.go index ca1465e..ad0271b 100644 --- a/append_test.go +++ b/append_test.go @@ -59,7 +59,7 @@ func TestAppend_NilNil(t *testing.T) { var err error result := AppendNonNil(err, nil) if result != nil { - t.Fatalf("non-nil errors: %s", result.GoString()) + t.Fatalf("non-nil errors: %s", result.Error()) } } @@ -68,7 +68,7 @@ func TestAppendNonNil(t *testing.T) { var err2 *Error result := AppendNonNil(err1, err2) if result != nil { - t.Fatalf("non-nil errors: %s", result.GoString()) + t.Fatalf("non-nil errors: %s", result.Error()) } } From c966ec95bb8bc60712b12e4649a75828e8ae35de Mon Sep 17 00:00:00 2001 From: Michael Spiegel Date: Tue, 16 Aug 2016 10:15:52 -0400 Subject: [PATCH 06/12] Bug fix AppendNonNil. Preserve input when errs list is empty. When the filtered errs list has zero length then preserve the input error. --- append.go | 6 +++--- append_test.go | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/append.go b/append.go index 0f1b68c..0e929b6 100644 --- a/append.go +++ b/append.go @@ -29,9 +29,9 @@ func removeNils(errs []error) []error { func AppendNonNil(err error, errs ...error) error { errs = removeNils(errs) - // Preserve nil value when no errors have occurred - if err == nil && len(errs) == 0 { - return nil + // Preserve input value when no errors have occurred + if len(errs) == 0 { + return err } return Append(err, errs...) diff --git a/append_test.go b/append_test.go index ad0271b..9374957 100644 --- a/append_test.go +++ b/append_test.go @@ -66,10 +66,15 @@ func TestAppend_NilNil(t *testing.T) { func TestAppendNonNil(t *testing.T) { var err1 error var err2 *Error - result := AppendNonNil(err1, err2) + result := AppendNonNil(err1, err2, nil, nil) if result != nil { t.Fatalf("non-nil errors: %s", result.Error()) } + err1 = errors.New("foo") + result = AppendNonNil(err1, err2, nil, nil) + if result != err1 { + t.Fatalf("input error modified: %s", result.Error()) + } } func TestAppend_NonError(t *testing.T) { From 4ad791156eeadbe03e7a7cbc8b40322b133d4c09 Mon Sep 17 00:00:00 2001 From: Michael Spiegel Date: Mon, 29 Aug 2016 13:44:48 -0400 Subject: [PATCH 07/12] Bug fix for struct error types. --- append.go | 12 +++++++++++- append_test.go | 13 +++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/append.go b/append.go index 0e929b6..0112164 100644 --- a/append.go +++ b/append.go @@ -10,7 +10,17 @@ import ( func removeNils(errs []error) []error { view := errs[:0] for _, err := range errs { - if err != nil && !reflect.ValueOf(err).IsNil() { + if err == nil { + continue + } + add := true + switch reflect.TypeOf(err).Kind() { + case reflect.Chan, reflect.Func, + reflect.Interface, reflect.Map, + reflect.Ptr, reflect.Slice: + add = !reflect.ValueOf(err).IsNil() + } + if add { view = append(view, err) } } diff --git a/append_test.go b/append_test.go index 9374957..61dd5dc 100644 --- a/append_test.go +++ b/append_test.go @@ -5,6 +5,10 @@ import ( "testing" ) +type TestError struct{} + +func (e TestError) Error() string { return "TestError" } + func TestRemoveNils(t *testing.T) { errs := []error{errors.New("foo"), nil, nil, errors.New("foo"), nil} errs = removeNils(errs) @@ -77,6 +81,15 @@ func TestAppendNonNil(t *testing.T) { } } +func TestAppendNonNilStruct(t *testing.T) { + var err1 error + var err3 TestError + result := AppendNonNil(err1, err3, nil) + if result == nil { + t.Fatalf("TestError was not appended") + } +} + func TestAppend_NonError(t *testing.T) { original := errors.New("foo") result := Append(original, errors.New("bar")) From a907df9538ca0d8284276a3e72e10f52900c0cbc Mon Sep 17 00:00:00 2001 From: Michael Spiegel Date: Wed, 19 Oct 2016 10:14:10 -0400 Subject: [PATCH 08/12] Preserve output value when only when error is produced --- append.go | 4 +++- append_test.go | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/append.go b/append.go index 0112164..ca179a4 100644 --- a/append.go +++ b/append.go @@ -40,10 +40,12 @@ func AppendNonNil(err error, errs ...error) error { errs = removeNils(errs) // Preserve input value when no errors have occurred + // Preserve output value when only one error is produced if len(errs) == 0 { return err + } else if (err == nil) && len(errs) == 1 { + return errs[0] } - return Append(err, errs...) } diff --git a/append_test.go b/append_test.go index 61dd5dc..79ffecc 100644 --- a/append_test.go +++ b/append_test.go @@ -79,6 +79,11 @@ func TestAppendNonNil(t *testing.T) { if result != err1 { t.Fatalf("input error modified: %s", result.Error()) } + err1 = errors.New("foo") + result = AppendNonNil(nil, err1, nil, nil) + if result != err1 { + t.Fatalf("input error modified: %s", result.Error()) + } } func TestAppendNonNilStruct(t *testing.T) { From 5b98f730da484eda5d00d3a864c2920bfefad255 Mon Sep 17 00:00:00 2001 From: Michael Spiegel Date: Thu, 9 Mar 2017 17:13:48 -0500 Subject: [PATCH 09/12] Replace Append() with AppendNonNil(). --- append.go | 12 ++++++------ append_test.go | 26 +++++++++++++------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/append.go b/append.go index ca179a4..6826205 100644 --- a/append.go +++ b/append.go @@ -27,7 +27,7 @@ func removeNils(errs []error) []error { return view } -// AppendNonNil is a helper function that will append more errors +// Append is a helper function that will append more errors // onto an Error in order to create a larger multi-error. // // If err is not a multierror.Error, then it will be turned into @@ -36,7 +36,7 @@ func removeNils(errs []error) []error { // // nil values in errs are filtered out. If the err is nil and // the length of filtered errs is zero then the function returns nil. -func AppendNonNil(err error, errs ...error) error { +func Append(err error, errs ...error) error { errs = removeNils(errs) // Preserve input value when no errors have occurred @@ -46,16 +46,16 @@ func AppendNonNil(err error, errs ...error) error { } else if (err == nil) && len(errs) == 1 { return errs[0] } - return Append(err, errs...) + return appendInternal(err, errs...) } -// Append is a helper function that will append more errors +// appendInternal is a helper function that will append more errors // onto an Error in order to create a larger multi-error. // // If err is not a multierror.Error, then it will be turned into // one. If any of the errs are multierr.Error, they will be flattened // one level into err. -func Append(err error, errs ...error) *Error { +func appendInternal(err error, errs ...error) *Error { switch err := err.(type) { case *Error: // Typed nils can reach here, so initialize if we are nil @@ -81,6 +81,6 @@ func Append(err error, errs ...error) *Error { } newErrs = append(newErrs, errs...) - return Append(&Error{}, newErrs...) + return appendInternal(&Error{}, newErrs...) } } diff --git a/append_test.go b/append_test.go index 79ffecc..9ccc3fc 100644 --- a/append_test.go +++ b/append_test.go @@ -22,20 +22,20 @@ func TestAppend_Error(t *testing.T) { Errors: []error{errors.New("foo")}, } - result := Append(original, errors.New("bar")) + result := Append(original, errors.New("bar")).(*Error) if len(result.Errors) != 2 { t.Fatalf("wrong len: %d", len(result.Errors)) } original = &Error{} - result = Append(original, errors.New("bar")) + result = Append(original, errors.New("bar")).(*Error) if len(result.Errors) != 1 { t.Fatalf("wrong len: %d", len(result.Errors)) } // Test when a typed nil is passed var e *Error - result = Append(e, errors.New("baz")) + result = Append(e, errors.New("baz")).(*Error) if len(result.Errors) != 1 { t.Fatalf("wrong len: %d", len(result.Errors)) } @@ -45,7 +45,7 @@ func TestAppend_Error(t *testing.T) { Errors: []error{errors.New("foo")}, } - result = Append(original, Append(nil, errors.New("foo"), errors.New("bar"))) + result = Append(original, Append(nil, errors.New("foo"), errors.New("bar"))).(*Error) if len(result.Errors) != 3 { t.Fatalf("wrong len: %d", len(result.Errors)) } @@ -54,14 +54,14 @@ func TestAppend_Error(t *testing.T) { func TestAppend_NilError(t *testing.T) { var err error result := Append(err, errors.New("bar")) - if len(result.Errors) != 1 { - t.Fatalf("wrong len: %d", len(result.Errors)) + if result.Error() != "bar" { + t.Fatalf("wrong error: %s", result.Error()) } } func TestAppend_NilNil(t *testing.T) { var err error - result := AppendNonNil(err, nil) + result := Append(err, nil) if result != nil { t.Fatalf("non-nil errors: %s", result.Error()) } @@ -70,17 +70,17 @@ func TestAppend_NilNil(t *testing.T) { func TestAppendNonNil(t *testing.T) { var err1 error var err2 *Error - result := AppendNonNil(err1, err2, nil, nil) + result := Append(err1, err2, nil, nil) if result != nil { t.Fatalf("non-nil errors: %s", result.Error()) } err1 = errors.New("foo") - result = AppendNonNil(err1, err2, nil, nil) + result = Append(err1, err2, nil, nil) if result != err1 { t.Fatalf("input error modified: %s", result.Error()) } err1 = errors.New("foo") - result = AppendNonNil(nil, err1, nil, nil) + result = Append(nil, err1, nil, nil) if result != err1 { t.Fatalf("input error modified: %s", result.Error()) } @@ -89,7 +89,7 @@ func TestAppendNonNil(t *testing.T) { func TestAppendNonNilStruct(t *testing.T) { var err1 error var err3 TestError - result := AppendNonNil(err1, err3, nil) + result := Append(err1, err3, nil) if result == nil { t.Fatalf("TestError was not appended") } @@ -97,7 +97,7 @@ func TestAppendNonNilStruct(t *testing.T) { func TestAppend_NonError(t *testing.T) { original := errors.New("foo") - result := Append(original, errors.New("bar")) + result := Append(original, errors.New("bar")).(*Error) if len(result.Errors) != 2 { t.Fatalf("wrong len: %d", len(result.Errors)) } @@ -105,7 +105,7 @@ func TestAppend_NonError(t *testing.T) { func TestAppend_NonError_Error(t *testing.T) { original := errors.New("foo") - result := Append(original, Append(nil, errors.New("bar"))) + result := Append(original, Append(nil, errors.New("bar"))).(*Error) if len(result.Errors) != 2 { t.Fatalf("wrong len: %d", len(result.Errors)) } From 065aa648c994f1f905c52e38e9bb23f4c7848737 Mon Sep 17 00:00:00 2001 From: Michael Spiegel Date: Thu, 9 Mar 2017 17:29:03 -0500 Subject: [PATCH 10/12] Update vendor.json Change root path to fork --- vendor/vendor.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/vendor.json b/vendor/vendor.json index 56de487..77a46ac 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -9,5 +9,5 @@ "revisionTime": "2014-10-28T05:47:10Z" } ], - "rootPath": "github.com/hashicorp/go-multierror" + "rootPath": "github.com/mspiegel/go-multierror" } From dd14681cfc94cc44aac3de90570aed8b9068a6fe Mon Sep 17 00:00:00 2001 From: Michael Spiegel Date: Wed, 22 Nov 2017 20:27:59 -0500 Subject: [PATCH 11/12] Cleanup. Remove unused functions. Clarify README.md documentation. --- README.md | 45 +-- multierror.go | 15 - multierror_test.go | 14 - prefix.go | 37 -- prefix_test.go | 33 -- scripts/deps.sh | 54 --- vendor/github.com/hashicorp/errwrap/LICENSE | 354 ------------------ vendor/github.com/hashicorp/errwrap/README.md | 89 ----- .../github.com/hashicorp/errwrap/errwrap.go | 169 --------- vendor/vendor.json | 13 - 10 files changed, 9 insertions(+), 814 deletions(-) delete mode 100644 prefix.go delete mode 100644 prefix_test.go delete mode 100755 scripts/deps.sh delete mode 100644 vendor/github.com/hashicorp/errwrap/LICENSE delete mode 100644 vendor/github.com/hashicorp/errwrap/README.md delete mode 100644 vendor/github.com/hashicorp/errwrap/errwrap.go delete mode 100644 vendor/vendor.json diff --git a/README.md b/README.md index ead5830..e744938 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,5 @@ # go-multierror -[![Build Status](http://img.shields.io/travis/hashicorp/go-multierror.svg?style=flat-square)][travis] -[![Go Documentation](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)][godocs] - -[travis]: https://travis-ci.org/hashicorp/go-multierror -[godocs]: https://godoc.org/github.com/hashicorp/go-multierror - `go-multierror` is a package for Go that provides a mechanism for representing a list of `error` values as a single `error`. @@ -14,16 +8,12 @@ be a list of errors. If the caller knows this, they can unwrap the list and access the errors. If the caller doesn't know, the error formats to a nice human-readable format. -`go-multierror` implements the -[errwrap](https://github.com/hashicorp/errwrap) interface so that it can -be used with that library, as well. +This is a fork of the hashicorp `go-multierror` library. In this +fork, nil error values are handled transparently. ## Installation and Docs -Install using `go get github.com/hashicorp/go-multierror`. - -Full documentation is available at -http://godoc.org/github.com/hashicorp/go-multierror +Install using `go get github.com/mspiegel/go-multierror`. ## Usage @@ -38,14 +28,12 @@ if the first argument is nil, a `multierror.Error`, or any other `error`, the function behaves as you would expect. ```go -var result error +var err, result error -if err := step1(); err != nil { - result = multierror.Append(result, err) -} -if err := step2(); err != nil { - result = multierror.Append(result, err) -} +err = step1() +result = multierror.Append(result, err) +err = step2() +result = multierror.Append(result, err) return result ``` @@ -79,19 +67,4 @@ if err := something(); err != nil { // Use merr.Errors } } -``` - -**Returning a multierror only if there are errors** - -If you build a `multierror.Error`, you can use the `ErrorOrNil` function -to return an `error` implementation only if there are errors to return: - -```go -var result *multierror.Error - -// ... accumulate errors here - -// Return the `error` only if errors were added to the multierror, otherwise -// return nil since there are no errors. -return result.ErrorOrNil() -``` +``` \ No newline at end of file diff --git a/multierror.go b/multierror.go index 2ea0827..70f0593 100644 --- a/multierror.go +++ b/multierror.go @@ -20,21 +20,6 @@ func (e *Error) Error() string { return fn(e.Errors) } -// ErrorOrNil returns an error interface if this Error represents -// a list of errors, or returns nil if the list of errors is empty. This -// function is useful at the end of accumulation to make sure that the value -// returned represents the existence of errors. -func (e *Error) ErrorOrNil() error { - if e == nil { - return nil - } - if len(e.Errors) == 0 { - return nil - } - - return e -} - func (e *Error) GoString() string { return fmt.Sprintf("*%#v", *e) } diff --git a/multierror_test.go b/multierror_test.go index 3e78079..60cbc18 100644 --- a/multierror_test.go +++ b/multierror_test.go @@ -43,20 +43,6 @@ func TestErrorError_default(t *testing.T) { } } -func TestErrorErrorOrNil(t *testing.T) { - err := new(Error) - if err.ErrorOrNil() != nil { - t.Fatalf("bad: %#v", err.ErrorOrNil()) - } - - err.Errors = []error{errors.New("foo")} - if v := err.ErrorOrNil(); v == nil { - t.Fatal("should not be nil") - } else if !reflect.DeepEqual(v, err) { - t.Fatalf("bad: %#v", v) - } -} - func TestErrorWrappedErrors(t *testing.T) { errors := []error{ errors.New("foo"), diff --git a/prefix.go b/prefix.go deleted file mode 100644 index 5c477ab..0000000 --- a/prefix.go +++ /dev/null @@ -1,37 +0,0 @@ -package multierror - -import ( - "fmt" - - "github.com/hashicorp/errwrap" -) - -// Prefix is a helper function that will prefix some text -// to the given error. If the error is a multierror.Error, then -// it will be prefixed to each wrapped error. -// -// This is useful to use when appending multiple multierrors -// together in order to give better scoping. -func Prefix(err error, prefix string) error { - if err == nil { - return nil - } - - format := fmt.Sprintf("%s {{err}}", prefix) - switch err := err.(type) { - case *Error: - // Typed nils can reach here, so initialize if we are nil - if err == nil { - err = new(Error) - } - - // Wrap each of the errors - for i, e := range err.Errors { - err.Errors[i] = errwrap.Wrapf(format, e) - } - - return err - default: - return errwrap.Wrapf(format, err) - } -} diff --git a/prefix_test.go b/prefix_test.go deleted file mode 100644 index 1d4a6f6..0000000 --- a/prefix_test.go +++ /dev/null @@ -1,33 +0,0 @@ -package multierror - -import ( - "errors" - "testing" -) - -func TestPrefix_Error(t *testing.T) { - original := &Error{ - Errors: []error{errors.New("foo")}, - } - - result := Prefix(original, "bar") - if result.(*Error).Errors[0].Error() != "bar foo" { - t.Fatalf("bad: %s", result) - } -} - -func TestPrefix_NilError(t *testing.T) { - var err error - result := Prefix(err, "bar") - if result != nil { - t.Fatalf("bad: %#v", result) - } -} - -func TestPrefix_NonError(t *testing.T) { - original := errors.New("foo") - result := Prefix(original, "bar") - if result.Error() != "bar foo" { - t.Fatalf("bad: %s", result) - } -} diff --git a/scripts/deps.sh b/scripts/deps.sh deleted file mode 100755 index 1d2fcf9..0000000 --- a/scripts/deps.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env bash -# -# This script updates dependencies using a temporary directory. This is required -# to avoid any auxillary dependencies that sneak into GOPATH. -set -e - -# Get the parent directory of where this script is. -SOURCE="${BASH_SOURCE[0]}" -while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done -DIR="$(cd -P "$(dirname "$SOURCE")/.." && pwd)" - -# Change into that directory -cd "$DIR" - -# Get the name from the directory -NAME=${NAME:-"$(basename $(pwd))"} - -# Announce -echo "==> Updating dependencies..." - -echo "--> Making tmpdir..." -tmpdir=$(mktemp -d) -function cleanup { - rm -rf "${tmpdir}" -} -trap cleanup EXIT - -export GOPATH="${tmpdir}" -export PATH="${tmpdir}/bin:$PATH" - -mkdir -p "${tmpdir}/src/github.com/hashicorp" -pushd "${tmpdir}/src/github.com/hashicorp" &>/dev/null - -echo "--> Copying ${NAME}..." -cp -R "$DIR" "${tmpdir}/src/github.com/hashicorp/${NAME}" -pushd "${tmpdir}/src/github.com/hashicorp/${NAME}" &>/dev/null -rm -rf vendor/ - -echo "--> Installing dependency manager..." -go get -u github.com/kardianos/govendor -govendor init - -echo "--> Installing all dependencies (may take some time)..." -govendor fetch -v +outside - -echo "--> Vendoring..." -govendor add +external - -echo "--> Moving into place..." -vpath="${tmpdir}/src/github.com/hashicorp/${NAME}/vendor" -popd &>/dev/null -popd &>/dev/null -rm -rf vendor/ -cp -R "${vpath}" . diff --git a/vendor/github.com/hashicorp/errwrap/LICENSE b/vendor/github.com/hashicorp/errwrap/LICENSE deleted file mode 100644 index c33dcc7..0000000 --- a/vendor/github.com/hashicorp/errwrap/LICENSE +++ /dev/null @@ -1,354 +0,0 @@ -Mozilla Public License, version 2.0 - -1. Definitions - -1.1. “Contributor” - - means each individual or legal entity that creates, contributes to the - creation of, or owns Covered Software. - -1.2. “Contributor Version” - - means the combination of the Contributions of others (if any) used by a - Contributor and that particular Contributor’s Contribution. - -1.3. “Contribution” - - means Covered Software of a particular Contributor. - -1.4. “Covered Software” - - means Source Code Form to which the initial Contributor has attached the - notice in Exhibit A, the Executable Form of such Source Code Form, and - Modifications of such Source Code Form, in each case including portions - thereof. - -1.5. “Incompatible With Secondary Licenses” - means - - a. that the initial Contributor has attached the notice described in - Exhibit B to the Covered Software; or - - b. that the Covered Software was made available under the terms of version - 1.1 or earlier of the License, but not also under the terms of a - Secondary License. - -1.6. “Executable Form” - - means any form of the work other than Source Code Form. - -1.7. “Larger Work” - - means a work that combines Covered Software with other material, in a separate - file or files, that is not Covered Software. - -1.8. “License” - - means this document. - -1.9. “Licensable” - - means having the right to grant, to the maximum extent possible, whether at the - time of the initial grant or subsequently, any and all of the rights conveyed by - this License. - -1.10. “Modifications” - - means any of the following: - - a. any file in Source Code Form that results from an addition to, deletion - from, or modification of the contents of Covered Software; or - - b. any new file in Source Code Form that contains any Covered Software. - -1.11. “Patent Claims” of a Contributor - - means any patent claim(s), including without limitation, method, process, - and apparatus claims, in any patent Licensable by such Contributor that - would be infringed, but for the grant of the License, by the making, - using, selling, offering for sale, having made, import, or transfer of - either its Contributions or its Contributor Version. - -1.12. “Secondary License” - - means either the GNU General Public License, Version 2.0, the GNU Lesser - General Public License, Version 2.1, the GNU Affero General Public - License, Version 3.0, or any later versions of those licenses. - -1.13. “Source Code Form” - - means the form of the work preferred for making modifications. - -1.14. “You” (or “Your”) - - means an individual or a legal entity exercising rights under this - License. For legal entities, “You” includes any entity that controls, is - controlled by, or is under common control with You. For purposes of this - definition, “control” means (a) the power, direct or indirect, to cause - the direction or management of such entity, whether by contract or - otherwise, or (b) ownership of more than fifty percent (50%) of the - outstanding shares or beneficial ownership of such entity. - - -2. License Grants and Conditions - -2.1. Grants - - Each Contributor hereby grants You a world-wide, royalty-free, - non-exclusive license: - - a. under intellectual property rights (other than patent or trademark) - Licensable by such Contributor to use, reproduce, make available, - modify, display, perform, distribute, and otherwise exploit its - Contributions, either on an unmodified basis, with Modifications, or as - part of a Larger Work; and - - b. under Patent Claims of such Contributor to make, use, sell, offer for - sale, have made, import, and otherwise transfer either its Contributions - or its Contributor Version. - -2.2. Effective Date - - The licenses granted in Section 2.1 with respect to any Contribution become - effective for each Contribution on the date the Contributor first distributes - such Contribution. - -2.3. Limitations on Grant Scope - - The licenses granted in this Section 2 are the only rights granted under this - License. No additional rights or licenses will be implied from the distribution - or licensing of Covered Software under this License. Notwithstanding Section - 2.1(b) above, no patent license is granted by a Contributor: - - a. for any code that a Contributor has removed from Covered Software; or - - b. for infringements caused by: (i) Your and any other third party’s - modifications of Covered Software, or (ii) the combination of its - Contributions with other software (except as part of its Contributor - Version); or - - c. under Patent Claims infringed by Covered Software in the absence of its - Contributions. - - This License does not grant any rights in the trademarks, service marks, or - logos of any Contributor (except as may be necessary to comply with the - notice requirements in Section 3.4). - -2.4. Subsequent Licenses - - No Contributor makes additional grants as a result of Your choice to - distribute the Covered Software under a subsequent version of this License - (see Section 10.2) or under the terms of a Secondary License (if permitted - under the terms of Section 3.3). - -2.5. Representation - - Each Contributor represents that the Contributor believes its Contributions - are its original creation(s) or it has sufficient rights to grant the - rights to its Contributions conveyed by this License. - -2.6. Fair Use - - This License is not intended to limit any rights You have under applicable - copyright doctrines of fair use, fair dealing, or other equivalents. - -2.7. Conditions - - Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in - Section 2.1. - - -3. Responsibilities - -3.1. Distribution of Source Form - - All distribution of Covered Software in Source Code Form, including any - Modifications that You create or to which You contribute, must be under the - terms of this License. You must inform recipients that the Source Code Form - of the Covered Software is governed by the terms of this License, and how - they can obtain a copy of this License. You may not attempt to alter or - restrict the recipients’ rights in the Source Code Form. - -3.2. Distribution of Executable Form - - If You distribute Covered Software in Executable Form then: - - a. such Covered Software must also be made available in Source Code Form, - as described in Section 3.1, and You must inform recipients of the - Executable Form how they can obtain a copy of such Source Code Form by - reasonable means in a timely manner, at a charge no more than the cost - of distribution to the recipient; and - - b. You may distribute such Executable Form under the terms of this License, - or sublicense it under different terms, provided that the license for - the Executable Form does not attempt to limit or alter the recipients’ - rights in the Source Code Form under this License. - -3.3. Distribution of a Larger Work - - You may create and distribute a Larger Work under terms of Your choice, - provided that You also comply with the requirements of this License for the - Covered Software. If the Larger Work is a combination of Covered Software - with a work governed by one or more Secondary Licenses, and the Covered - Software is not Incompatible With Secondary Licenses, this License permits - You to additionally distribute such Covered Software under the terms of - such Secondary License(s), so that the recipient of the Larger Work may, at - their option, further distribute the Covered Software under the terms of - either this License or such Secondary License(s). - -3.4. Notices - - You may not remove or alter the substance of any license notices (including - copyright notices, patent notices, disclaimers of warranty, or limitations - of liability) contained within the Source Code Form of the Covered - Software, except that You may alter any license notices to the extent - required to remedy known factual inaccuracies. - -3.5. Application of Additional Terms - - You may choose to offer, and to charge a fee for, warranty, support, - indemnity or liability obligations to one or more recipients of Covered - Software. However, You may do so only on Your own behalf, and not on behalf - of any Contributor. You must make it absolutely clear that any such - warranty, support, indemnity, or liability obligation is offered by You - alone, and You hereby agree to indemnify every Contributor for any - liability incurred by such Contributor as a result of warranty, support, - indemnity or liability terms You offer. You may include additional - disclaimers of warranty and limitations of liability specific to any - jurisdiction. - -4. Inability to Comply Due to Statute or Regulation - - If it is impossible for You to comply with any of the terms of this License - with respect to some or all of the Covered Software due to statute, judicial - order, or regulation then You must: (a) comply with the terms of this License - to the maximum extent possible; and (b) describe the limitations and the code - they affect. Such description must be placed in a text file included with all - distributions of the Covered Software under this License. Except to the - extent prohibited by statute or regulation, such description must be - sufficiently detailed for a recipient of ordinary skill to be able to - understand it. - -5. Termination - -5.1. The rights granted under this License will terminate automatically if You - fail to comply with any of its terms. However, if You become compliant, - then the rights granted under this License from a particular Contributor - are reinstated (a) provisionally, unless and until such Contributor - explicitly and finally terminates Your grants, and (b) on an ongoing basis, - if such Contributor fails to notify You of the non-compliance by some - reasonable means prior to 60 days after You have come back into compliance. - Moreover, Your grants from a particular Contributor are reinstated on an - ongoing basis if such Contributor notifies You of the non-compliance by - some reasonable means, this is the first time You have received notice of - non-compliance with this License from such Contributor, and You become - compliant prior to 30 days after Your receipt of the notice. - -5.2. If You initiate litigation against any entity by asserting a patent - infringement claim (excluding declaratory judgment actions, counter-claims, - and cross-claims) alleging that a Contributor Version directly or - indirectly infringes any patent, then the rights granted to You by any and - all Contributors for the Covered Software under Section 2.1 of this License - shall terminate. - -5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user - license agreements (excluding distributors and resellers) which have been - validly granted by You or Your distributors under this License prior to - termination shall survive termination. - -6. Disclaimer of Warranty - - Covered Software is provided under this License on an “as is” basis, without - warranty of any kind, either expressed, implied, or statutory, including, - without limitation, warranties that the Covered Software is free of defects, - merchantable, fit for a particular purpose or non-infringing. The entire - risk as to the quality and performance of the Covered Software is with You. - Should any Covered Software prove defective in any respect, You (not any - Contributor) assume the cost of any necessary servicing, repair, or - correction. This disclaimer of warranty constitutes an essential part of this - License. No use of any Covered Software is authorized under this License - except under this disclaimer. - -7. Limitation of Liability - - Under no circumstances and under no legal theory, whether tort (including - negligence), contract, or otherwise, shall any Contributor, or anyone who - distributes Covered Software as permitted above, be liable to You for any - direct, indirect, special, incidental, or consequential damages of any - character including, without limitation, damages for lost profits, loss of - goodwill, work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses, even if such party shall have been - informed of the possibility of such damages. This limitation of liability - shall not apply to liability for death or personal injury resulting from such - party’s negligence to the extent applicable law prohibits such limitation. - Some jurisdictions do not allow the exclusion or limitation of incidental or - consequential damages, so this exclusion and limitation may not apply to You. - -8. Litigation - - Any litigation relating to this License may be brought only in the courts of - a jurisdiction where the defendant maintains its principal place of business - and such litigation shall be governed by laws of that jurisdiction, without - reference to its conflict-of-law provisions. Nothing in this Section shall - prevent a party’s ability to bring cross-claims or counter-claims. - -9. Miscellaneous - - This License represents the complete agreement concerning the subject matter - hereof. If any provision of this License is held to be unenforceable, such - provision shall be reformed only to the extent necessary to make it - enforceable. Any law or regulation which provides that the language of a - contract shall be construed against the drafter shall not be used to construe - this License against a Contributor. - - -10. Versions of the License - -10.1. New Versions - - Mozilla Foundation is the license steward. Except as provided in Section - 10.3, no one other than the license steward has the right to modify or - publish new versions of this License. Each version will be given a - distinguishing version number. - -10.2. Effect of New Versions - - You may distribute the Covered Software under the terms of the version of - the License under which You originally received the Covered Software, or - under the terms of any subsequent version published by the license - steward. - -10.3. Modified Versions - - If you create software not governed by this License, and you want to - create a new license for such software, you may create and use a modified - version of this License if you rename the license and remove any - references to the name of the license steward (except to note that such - modified license differs from this License). - -10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses - If You choose to distribute Source Code Form that is Incompatible With - Secondary Licenses under the terms of this version of the License, the - notice described in Exhibit B of this License must be attached. - -Exhibit A - Source Code Form License Notice - - This Source Code Form is subject to the - terms of the Mozilla Public License, v. - 2.0. If a copy of the MPL was not - distributed with this file, You can - obtain one at - http://mozilla.org/MPL/2.0/. - -If it is not possible or desirable to put the notice in a particular file, then -You may include the notice in a location (such as a LICENSE file in a relevant -directory) where a recipient would be likely to look for such a notice. - -You may add additional accurate notices of copyright ownership. - -Exhibit B - “Incompatible With Secondary Licenses” Notice - - This Source Code Form is “Incompatible - With Secondary Licenses”, as defined by - the Mozilla Public License, v. 2.0. - diff --git a/vendor/github.com/hashicorp/errwrap/README.md b/vendor/github.com/hashicorp/errwrap/README.md deleted file mode 100644 index 1c95f59..0000000 --- a/vendor/github.com/hashicorp/errwrap/README.md +++ /dev/null @@ -1,89 +0,0 @@ -# errwrap - -`errwrap` is a package for Go that formalizes the pattern of wrapping errors -and checking if an error contains another error. - -There is a common pattern in Go of taking a returned `error` value and -then wrapping it (such as with `fmt.Errorf`) before returning it. The problem -with this pattern is that you completely lose the original `error` structure. - -Arguably the _correct_ approach is that you should make a custom structure -implementing the `error` interface, and have the original error as a field -on that structure, such [as this example](http://golang.org/pkg/os/#PathError). -This is a good approach, but you have to know the entire chain of possible -rewrapping that happens, when you might just care about one. - -`errwrap` formalizes this pattern (it doesn't matter what approach you use -above) by giving a single interface for wrapping errors, checking if a specific -error is wrapped, and extracting that error. - -## Installation and Docs - -Install using `go get github.com/hashicorp/errwrap`. - -Full documentation is available at -http://godoc.org/github.com/hashicorp/errwrap - -## Usage - -#### Basic Usage - -Below is a very basic example of its usage: - -```go -// A function that always returns an error, but wraps it, like a real -// function might. -func tryOpen() error { - _, err := os.Open("/i/dont/exist") - if err != nil { - return errwrap.Wrapf("Doesn't exist: {{err}}", err) - } - - return nil -} - -func main() { - err := tryOpen() - - // We can use the Contains helpers to check if an error contains - // another error. It is safe to do this with a nil error, or with - // an error that doesn't even use the errwrap package. - if errwrap.Contains(err, ErrNotExist) { - // Do something - } - if errwrap.ContainsType(err, new(os.PathError)) { - // Do something - } - - // Or we can use the associated `Get` functions to just extract - // a specific error. This would return nil if that specific error doesn't - // exist. - perr := errwrap.GetType(err, new(os.PathError)) -} -``` - -#### Custom Types - -If you're already making custom types that properly wrap errors, then -you can get all the functionality of `errwraps.Contains` and such by -implementing the `Wrapper` interface with just one function. Example: - -```go -type AppError { - Code ErrorCode - Err error -} - -func (e *AppError) WrappedErrors() []error { - return []error{e.Err} -} -``` - -Now this works: - -```go -err := &AppError{Err: fmt.Errorf("an error")} -if errwrap.ContainsType(err, fmt.Errorf("")) { - // This will work! -} -``` diff --git a/vendor/github.com/hashicorp/errwrap/errwrap.go b/vendor/github.com/hashicorp/errwrap/errwrap.go deleted file mode 100644 index a733bef..0000000 --- a/vendor/github.com/hashicorp/errwrap/errwrap.go +++ /dev/null @@ -1,169 +0,0 @@ -// Package errwrap implements methods to formalize error wrapping in Go. -// -// All of the top-level functions that take an `error` are built to be able -// to take any error, not just wrapped errors. This allows you to use errwrap -// without having to type-check and type-cast everywhere. -package errwrap - -import ( - "errors" - "reflect" - "strings" -) - -// WalkFunc is the callback called for Walk. -type WalkFunc func(error) - -// Wrapper is an interface that can be implemented by custom types to -// have all the Contains, Get, etc. functions in errwrap work. -// -// When Walk reaches a Wrapper, it will call the callback for every -// wrapped error in addition to the wrapper itself. Since all the top-level -// functions in errwrap use Walk, this means that all those functions work -// with your custom type. -type Wrapper interface { - WrappedErrors() []error -} - -// Wrap defines that outer wraps inner, returning an error type that -// can be cleanly used with the other methods in this package, such as -// Contains, GetAll, etc. -// -// This function won't modify the error message at all (the outer message -// will be used). -func Wrap(outer, inner error) error { - return &wrappedError{ - Outer: outer, - Inner: inner, - } -} - -// Wrapf wraps an error with a formatting message. This is similar to using -// `fmt.Errorf` to wrap an error. If you're using `fmt.Errorf` to wrap -// errors, you should replace it with this. -// -// format is the format of the error message. The string '{{err}}' will -// be replaced with the original error message. -func Wrapf(format string, err error) error { - outerMsg := "" - if err != nil { - outerMsg = err.Error() - } - - outer := errors.New(strings.Replace( - format, "{{err}}", outerMsg, -1)) - - return Wrap(outer, err) -} - -// Contains checks if the given error contains an error with the -// message msg. If err is not a wrapped error, this will always return -// false unless the error itself happens to match this msg. -func Contains(err error, msg string) bool { - return len(GetAll(err, msg)) > 0 -} - -// ContainsType checks if the given error contains an error with -// the same concrete type as v. If err is not a wrapped error, this will -// check the err itself. -func ContainsType(err error, v interface{}) bool { - return len(GetAllType(err, v)) > 0 -} - -// Get is the same as GetAll but returns the deepest matching error. -func Get(err error, msg string) error { - es := GetAll(err, msg) - if len(es) > 0 { - return es[len(es)-1] - } - - return nil -} - -// GetType is the same as GetAllType but returns the deepest matching error. -func GetType(err error, v interface{}) error { - es := GetAllType(err, v) - if len(es) > 0 { - return es[len(es)-1] - } - - return nil -} - -// GetAll gets all the errors that might be wrapped in err with the -// given message. The order of the errors is such that the outermost -// matching error (the most recent wrap) is index zero, and so on. -func GetAll(err error, msg string) []error { - var result []error - - Walk(err, func(err error) { - if err.Error() == msg { - result = append(result, err) - } - }) - - return result -} - -// GetAllType gets all the errors that are the same type as v. -// -// The order of the return value is the same as described in GetAll. -func GetAllType(err error, v interface{}) []error { - var result []error - - var search string - if v != nil { - search = reflect.TypeOf(v).String() - } - Walk(err, func(err error) { - var needle string - if err != nil { - needle = reflect.TypeOf(err).String() - } - - if needle == search { - result = append(result, err) - } - }) - - return result -} - -// Walk walks all the wrapped errors in err and calls the callback. If -// err isn't a wrapped error, this will be called once for err. If err -// is a wrapped error, the callback will be called for both the wrapper -// that implements error as well as the wrapped error itself. -func Walk(err error, cb WalkFunc) { - if err == nil { - return - } - - switch e := err.(type) { - case *wrappedError: - cb(e.Outer) - Walk(e.Inner, cb) - case Wrapper: - cb(err) - - for _, err := range e.WrappedErrors() { - Walk(err, cb) - } - default: - cb(err) - } -} - -// wrappedError is an implementation of error that has both the -// outer and inner errors. -type wrappedError struct { - Outer error - Inner error -} - -func (w *wrappedError) Error() string { - return w.Outer.Error() -} - -func (w *wrappedError) WrappedErrors() []error { - return []error{w.Outer, w.Inner} -} diff --git a/vendor/vendor.json b/vendor/vendor.json deleted file mode 100644 index 77a46ac..0000000 --- a/vendor/vendor.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "comment": "", - "ignore": "test", - "package": [ - { - "checksumSHA1": "cdOCt0Yb+hdErz8NAQqayxPmRsY=", - "path": "github.com/hashicorp/errwrap", - "revision": "7554cd9344cec97297fa6649b055a8c98c2a1e55", - "revisionTime": "2014-10-28T05:47:10Z" - } - ], - "rootPath": "github.com/mspiegel/go-multierror" -} From ea68e724609afabf6bebe1eaacabddedfebfeb83 Mon Sep 17 00:00:00 2001 From: Michael Spiegel Date: Thu, 23 Nov 2017 15:01:49 -0500 Subject: [PATCH 12/12] Delete .travis.yml --- .travis.yml | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 4b865d1..0000000 --- a/.travis.yml +++ /dev/null @@ -1,12 +0,0 @@ -sudo: false - -language: go - -go: - - 1.6 - -branches: - only: - - master - -script: make test testrace