refactor: log with zap
This commit is contained in:
		
							
								
								
									
										15
									
								
								vendor/go.uber.org/multierr/.codecov.yml
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								vendor/go.uber.org/multierr/.codecov.yml
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
			
		||||
coverage:
 | 
			
		||||
  range: 80..100
 | 
			
		||||
  round: down
 | 
			
		||||
  precision: 2
 | 
			
		||||
 | 
			
		||||
  status:
 | 
			
		||||
    project:                   # measuring the overall project coverage
 | 
			
		||||
      default:                 # context, you can create multiple ones with custom titles
 | 
			
		||||
        enabled: yes           # must be yes|true to enable this status
 | 
			
		||||
        target: 100            # specify the target coverage for each commit status
 | 
			
		||||
                               #   option: "auto" (must increase from parent commit or pull request base)
 | 
			
		||||
                               #   option: "X%" a static target percentage to hit
 | 
			
		||||
        if_not_found: success  # if parent is not found report status as success, error, or failure
 | 
			
		||||
        if_ci_failed: error    # if ci fails report status as success, error, or failure
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										4
									
								
								vendor/go.uber.org/multierr/.gitignore
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								vendor/go.uber.org/multierr/.gitignore
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,4 @@
 | 
			
		||||
/vendor
 | 
			
		||||
cover.html
 | 
			
		||||
cover.out
 | 
			
		||||
/bin
 | 
			
		||||
							
								
								
									
										23
									
								
								vendor/go.uber.org/multierr/.travis.yml
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								vendor/go.uber.org/multierr/.travis.yml
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
			
		||||
sudo: false
 | 
			
		||||
language: go
 | 
			
		||||
go_import_path: go.uber.org/multierr
 | 
			
		||||
 | 
			
		||||
env:
 | 
			
		||||
  global:
 | 
			
		||||
    - GO111MODULE=on
 | 
			
		||||
 | 
			
		||||
go:
 | 
			
		||||
  - oldstable
 | 
			
		||||
  - stable
 | 
			
		||||
 | 
			
		||||
before_install:
 | 
			
		||||
- go version
 | 
			
		||||
 | 
			
		||||
script:
 | 
			
		||||
- |
 | 
			
		||||
  set -e
 | 
			
		||||
  make lint
 | 
			
		||||
  make cover
 | 
			
		||||
 | 
			
		||||
after_success:
 | 
			
		||||
- bash <(curl -s https://codecov.io/bash)
 | 
			
		||||
							
								
								
									
										60
									
								
								vendor/go.uber.org/multierr/CHANGELOG.md
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								vendor/go.uber.org/multierr/CHANGELOG.md
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,60 @@
 | 
			
		||||
Releases
 | 
			
		||||
========
 | 
			
		||||
 | 
			
		||||
v1.6.0 (2020-09-14)
 | 
			
		||||
===================
 | 
			
		||||
 | 
			
		||||
-   Actually drop library dependency on development-time tooling.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
v1.5.0 (2020-02-24)
 | 
			
		||||
===================
 | 
			
		||||
 | 
			
		||||
-   Drop library dependency on development-time tooling.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
v1.4.0 (2019-11-04)
 | 
			
		||||
===================
 | 
			
		||||
 | 
			
		||||
-   Add `AppendInto` function to more ergonomically build errors inside a
 | 
			
		||||
    loop.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
v1.3.0 (2019-10-29)
 | 
			
		||||
===================
 | 
			
		||||
 | 
			
		||||
-   Switch to Go modules.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
v1.2.0 (2019-09-26)
 | 
			
		||||
===================
 | 
			
		||||
 | 
			
		||||
-   Support extracting and matching against wrapped errors with `errors.As`
 | 
			
		||||
    and `errors.Is`.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
v1.1.0 (2017-06-30)
 | 
			
		||||
===================
 | 
			
		||||
 | 
			
		||||
-   Added an `Errors(error) []error` function to extract the underlying list of
 | 
			
		||||
    errors for a multierr error.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
v1.0.0 (2017-05-31)
 | 
			
		||||
===================
 | 
			
		||||
 | 
			
		||||
No changes since v0.2.0. This release is committing to making no breaking
 | 
			
		||||
changes to the current API in the 1.X series.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
v0.2.0 (2017-04-11)
 | 
			
		||||
===================
 | 
			
		||||
 | 
			
		||||
-   Repeatedly appending to the same error is now faster due to fewer
 | 
			
		||||
    allocations.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
v0.1.0 (2017-31-03)
 | 
			
		||||
===================
 | 
			
		||||
 | 
			
		||||
-   Initial release
 | 
			
		||||
							
								
								
									
										19
									
								
								vendor/go.uber.org/multierr/LICENSE.txt
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								vendor/go.uber.org/multierr/LICENSE.txt
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
			
		||||
Copyright (c) 2017 Uber Technologies, Inc.
 | 
			
		||||
 | 
			
		||||
Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
			
		||||
of this software and associated documentation files (the "Software"), to deal
 | 
			
		||||
in the Software without restriction, including without limitation the rights
 | 
			
		||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
			
		||||
copies of the Software, and to permit persons to whom the Software is
 | 
			
		||||
furnished to do so, subject to the following conditions:
 | 
			
		||||
 | 
			
		||||
The above copyright notice and this permission notice shall be included in
 | 
			
		||||
all copies or substantial portions of the Software.
 | 
			
		||||
 | 
			
		||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
			
		||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
			
		||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
			
		||||
THE SOFTWARE.
 | 
			
		||||
							
								
								
									
										42
									
								
								vendor/go.uber.org/multierr/Makefile
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								vendor/go.uber.org/multierr/Makefile
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,42 @@
 | 
			
		||||
# Directory to put `go install`ed binaries in.
 | 
			
		||||
export GOBIN ?= $(shell pwd)/bin
 | 
			
		||||
 | 
			
		||||
GO_FILES := $(shell \
 | 
			
		||||
	find . '(' -path '*/.*' -o -path './vendor' ')' -prune \
 | 
			
		||||
	-o -name '*.go' -print | cut -b3-)
 | 
			
		||||
 | 
			
		||||
.PHONY: build
 | 
			
		||||
build:
 | 
			
		||||
	go build ./...
 | 
			
		||||
 | 
			
		||||
.PHONY: test
 | 
			
		||||
test:
 | 
			
		||||
	go test -race ./...
 | 
			
		||||
 | 
			
		||||
.PHONY: gofmt
 | 
			
		||||
gofmt:
 | 
			
		||||
	$(eval FMT_LOG := $(shell mktemp -t gofmt.XXXXX))
 | 
			
		||||
	@gofmt -e -s -l $(GO_FILES) > $(FMT_LOG) || true
 | 
			
		||||
	@[ ! -s "$(FMT_LOG)" ] || (echo "gofmt failed:" | cat - $(FMT_LOG) && false)
 | 
			
		||||
 | 
			
		||||
.PHONY: golint
 | 
			
		||||
golint:
 | 
			
		||||
	@cd tools && go install golang.org/x/lint/golint
 | 
			
		||||
	@$(GOBIN)/golint ./...
 | 
			
		||||
 | 
			
		||||
.PHONY: staticcheck
 | 
			
		||||
staticcheck:
 | 
			
		||||
	@cd tools && go install honnef.co/go/tools/cmd/staticcheck
 | 
			
		||||
	@$(GOBIN)/staticcheck ./...
 | 
			
		||||
 | 
			
		||||
.PHONY: lint
 | 
			
		||||
lint: gofmt golint staticcheck
 | 
			
		||||
 | 
			
		||||
.PHONY: cover
 | 
			
		||||
cover:
 | 
			
		||||
	go test -coverprofile=cover.out -coverpkg=./... -v ./...
 | 
			
		||||
	go tool cover -html=cover.out -o cover.html
 | 
			
		||||
 | 
			
		||||
update-license:
 | 
			
		||||
	@cd tools && go install go.uber.org/tools/update-license
 | 
			
		||||
	@$(GOBIN)/update-license $(GO_FILES)
 | 
			
		||||
							
								
								
									
										23
									
								
								vendor/go.uber.org/multierr/README.md
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								vendor/go.uber.org/multierr/README.md
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
			
		||||
# multierr [![GoDoc][doc-img]][doc] [![Build Status][ci-img]][ci] [![Coverage Status][cov-img]][cov]
 | 
			
		||||
 | 
			
		||||
`multierr` allows combining one or more Go `error`s together.
 | 
			
		||||
 | 
			
		||||
## Installation
 | 
			
		||||
 | 
			
		||||
    go get -u go.uber.org/multierr
 | 
			
		||||
 | 
			
		||||
## Status
 | 
			
		||||
 | 
			
		||||
Stable: No breaking changes will be made before 2.0.
 | 
			
		||||
 | 
			
		||||
-------------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
Released under the [MIT License].
 | 
			
		||||
 | 
			
		||||
[MIT License]: LICENSE.txt
 | 
			
		||||
[doc-img]: https://godoc.org/go.uber.org/multierr?status.svg
 | 
			
		||||
[doc]: https://godoc.org/go.uber.org/multierr
 | 
			
		||||
[ci-img]: https://travis-ci.com/uber-go/multierr.svg?branch=master
 | 
			
		||||
[cov-img]: https://codecov.io/gh/uber-go/multierr/branch/master/graph/badge.svg
 | 
			
		||||
[ci]: https://travis-ci.com/uber-go/multierr
 | 
			
		||||
[cov]: https://codecov.io/gh/uber-go/multierr
 | 
			
		||||
							
								
								
									
										449
									
								
								vendor/go.uber.org/multierr/error.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										449
									
								
								vendor/go.uber.org/multierr/error.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,449 @@
 | 
			
		||||
// Copyright (c) 2019 Uber Technologies, Inc.
 | 
			
		||||
//
 | 
			
		||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
			
		||||
// of this software and associated documentation files (the "Software"), to deal
 | 
			
		||||
// in the Software without restriction, including without limitation the rights
 | 
			
		||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
			
		||||
// copies of the Software, and to permit persons to whom the Software is
 | 
			
		||||
// furnished to do so, subject to the following conditions:
 | 
			
		||||
//
 | 
			
		||||
// The above copyright notice and this permission notice shall be included in
 | 
			
		||||
// all copies or substantial portions of the Software.
 | 
			
		||||
//
 | 
			
		||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
			
		||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
			
		||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
			
		||||
// THE SOFTWARE.
 | 
			
		||||
 | 
			
		||||
// Package multierr allows combining one or more errors together.
 | 
			
		||||
//
 | 
			
		||||
// Overview
 | 
			
		||||
//
 | 
			
		||||
// Errors can be combined with the use of the Combine function.
 | 
			
		||||
//
 | 
			
		||||
// 	multierr.Combine(
 | 
			
		||||
// 		reader.Close(),
 | 
			
		||||
// 		writer.Close(),
 | 
			
		||||
// 		conn.Close(),
 | 
			
		||||
// 	)
 | 
			
		||||
//
 | 
			
		||||
// If only two errors are being combined, the Append function may be used
 | 
			
		||||
// instead.
 | 
			
		||||
//
 | 
			
		||||
// 	err = multierr.Append(reader.Close(), writer.Close())
 | 
			
		||||
//
 | 
			
		||||
// This makes it possible to record resource cleanup failures from deferred
 | 
			
		||||
// blocks with the help of named return values.
 | 
			
		||||
//
 | 
			
		||||
// 	func sendRequest(req Request) (err error) {
 | 
			
		||||
// 		conn, err := openConnection()
 | 
			
		||||
// 		if err != nil {
 | 
			
		||||
// 			return err
 | 
			
		||||
// 		}
 | 
			
		||||
// 		defer func() {
 | 
			
		||||
// 			err = multierr.Append(err, conn.Close())
 | 
			
		||||
// 		}()
 | 
			
		||||
// 		// ...
 | 
			
		||||
// 	}
 | 
			
		||||
//
 | 
			
		||||
// The underlying list of errors for a returned error object may be retrieved
 | 
			
		||||
// with the Errors function.
 | 
			
		||||
//
 | 
			
		||||
// 	errors := multierr.Errors(err)
 | 
			
		||||
// 	if len(errors) > 0 {
 | 
			
		||||
// 		fmt.Println("The following errors occurred:", errors)
 | 
			
		||||
// 	}
 | 
			
		||||
//
 | 
			
		||||
// Advanced Usage
 | 
			
		||||
//
 | 
			
		||||
// Errors returned by Combine and Append MAY implement the following
 | 
			
		||||
// interface.
 | 
			
		||||
//
 | 
			
		||||
// 	type errorGroup interface {
 | 
			
		||||
// 		// Returns a slice containing the underlying list of errors.
 | 
			
		||||
// 		//
 | 
			
		||||
// 		// This slice MUST NOT be modified by the caller.
 | 
			
		||||
// 		Errors() []error
 | 
			
		||||
// 	}
 | 
			
		||||
//
 | 
			
		||||
// Note that if you need access to list of errors behind a multierr error, you
 | 
			
		||||
// should prefer using the Errors function. That said, if you need cheap
 | 
			
		||||
// read-only access to the underlying errors slice, you can attempt to cast
 | 
			
		||||
// the error to this interface. You MUST handle the failure case gracefully
 | 
			
		||||
// because errors returned by Combine and Append are not guaranteed to
 | 
			
		||||
// implement this interface.
 | 
			
		||||
//
 | 
			
		||||
// 	var errors []error
 | 
			
		||||
// 	group, ok := err.(errorGroup)
 | 
			
		||||
// 	if ok {
 | 
			
		||||
// 		errors = group.Errors()
 | 
			
		||||
// 	} else {
 | 
			
		||||
// 		errors = []error{err}
 | 
			
		||||
// 	}
 | 
			
		||||
package multierr // import "go.uber.org/multierr"
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"bytes"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"sync"
 | 
			
		||||
 | 
			
		||||
	"go.uber.org/atomic"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	// Separator for single-line error messages.
 | 
			
		||||
	_singlelineSeparator = []byte("; ")
 | 
			
		||||
 | 
			
		||||
	// Prefix for multi-line messages
 | 
			
		||||
	_multilinePrefix = []byte("the following errors occurred:")
 | 
			
		||||
 | 
			
		||||
	// Prefix for the first and following lines of an item in a list of
 | 
			
		||||
	// multi-line error messages.
 | 
			
		||||
	//
 | 
			
		||||
	// For example, if a single item is:
 | 
			
		||||
	//
 | 
			
		||||
	// 	foo
 | 
			
		||||
	// 	bar
 | 
			
		||||
	//
 | 
			
		||||
	// It will become,
 | 
			
		||||
	//
 | 
			
		||||
	// 	 -  foo
 | 
			
		||||
	// 	    bar
 | 
			
		||||
	_multilineSeparator = []byte("\n -  ")
 | 
			
		||||
	_multilineIndent    = []byte("    ")
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// _bufferPool is a pool of bytes.Buffers.
 | 
			
		||||
var _bufferPool = sync.Pool{
 | 
			
		||||
	New: func() interface{} {
 | 
			
		||||
		return &bytes.Buffer{}
 | 
			
		||||
	},
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type errorGroup interface {
 | 
			
		||||
	Errors() []error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Errors returns a slice containing zero or more errors that the supplied
 | 
			
		||||
// error is composed of. If the error is nil, a nil slice is returned.
 | 
			
		||||
//
 | 
			
		||||
// 	err := multierr.Append(r.Close(), w.Close())
 | 
			
		||||
// 	errors := multierr.Errors(err)
 | 
			
		||||
//
 | 
			
		||||
// If the error is not composed of other errors, the returned slice contains
 | 
			
		||||
// just the error that was passed in.
 | 
			
		||||
//
 | 
			
		||||
// Callers of this function are free to modify the returned slice.
 | 
			
		||||
func Errors(err error) []error {
 | 
			
		||||
	if err == nil {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Note that we're casting to multiError, not errorGroup. Our contract is
 | 
			
		||||
	// that returned errors MAY implement errorGroup. Errors, however, only
 | 
			
		||||
	// has special behavior for multierr-specific error objects.
 | 
			
		||||
	//
 | 
			
		||||
	// This behavior can be expanded in the future but I think it's prudent to
 | 
			
		||||
	// start with as little as possible in terms of contract and possibility
 | 
			
		||||
	// of misuse.
 | 
			
		||||
	eg, ok := err.(*multiError)
 | 
			
		||||
	if !ok {
 | 
			
		||||
		return []error{err}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	errors := eg.Errors()
 | 
			
		||||
	result := make([]error, len(errors))
 | 
			
		||||
	copy(result, errors)
 | 
			
		||||
	return result
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// multiError is an error that holds one or more errors.
 | 
			
		||||
//
 | 
			
		||||
// An instance of this is guaranteed to be non-empty and flattened. That is,
 | 
			
		||||
// none of the errors inside multiError are other multiErrors.
 | 
			
		||||
//
 | 
			
		||||
// multiError formats to a semi-colon delimited list of error messages with
 | 
			
		||||
// %v and with a more readable multi-line format with %+v.
 | 
			
		||||
type multiError struct {
 | 
			
		||||
	copyNeeded atomic.Bool
 | 
			
		||||
	errors     []error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var _ errorGroup = (*multiError)(nil)
 | 
			
		||||
 | 
			
		||||
// Errors returns the list of underlying errors.
 | 
			
		||||
//
 | 
			
		||||
// This slice MUST NOT be modified.
 | 
			
		||||
func (merr *multiError) Errors() []error {
 | 
			
		||||
	if merr == nil {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
	return merr.errors
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (merr *multiError) Error() string {
 | 
			
		||||
	if merr == nil {
 | 
			
		||||
		return ""
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	buff := _bufferPool.Get().(*bytes.Buffer)
 | 
			
		||||
	buff.Reset()
 | 
			
		||||
 | 
			
		||||
	merr.writeSingleline(buff)
 | 
			
		||||
 | 
			
		||||
	result := buff.String()
 | 
			
		||||
	_bufferPool.Put(buff)
 | 
			
		||||
	return result
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (merr *multiError) Format(f fmt.State, c rune) {
 | 
			
		||||
	if c == 'v' && f.Flag('+') {
 | 
			
		||||
		merr.writeMultiline(f)
 | 
			
		||||
	} else {
 | 
			
		||||
		merr.writeSingleline(f)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (merr *multiError) writeSingleline(w io.Writer) {
 | 
			
		||||
	first := true
 | 
			
		||||
	for _, item := range merr.errors {
 | 
			
		||||
		if first {
 | 
			
		||||
			first = false
 | 
			
		||||
		} else {
 | 
			
		||||
			w.Write(_singlelineSeparator)
 | 
			
		||||
		}
 | 
			
		||||
		io.WriteString(w, item.Error())
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (merr *multiError) writeMultiline(w io.Writer) {
 | 
			
		||||
	w.Write(_multilinePrefix)
 | 
			
		||||
	for _, item := range merr.errors {
 | 
			
		||||
		w.Write(_multilineSeparator)
 | 
			
		||||
		writePrefixLine(w, _multilineIndent, fmt.Sprintf("%+v", item))
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Writes s to the writer with the given prefix added before each line after
 | 
			
		||||
// the first.
 | 
			
		||||
func writePrefixLine(w io.Writer, prefix []byte, s string) {
 | 
			
		||||
	first := true
 | 
			
		||||
	for len(s) > 0 {
 | 
			
		||||
		if first {
 | 
			
		||||
			first = false
 | 
			
		||||
		} else {
 | 
			
		||||
			w.Write(prefix)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		idx := strings.IndexByte(s, '\n')
 | 
			
		||||
		if idx < 0 {
 | 
			
		||||
			idx = len(s) - 1
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		io.WriteString(w, s[:idx+1])
 | 
			
		||||
		s = s[idx+1:]
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type inspectResult struct {
 | 
			
		||||
	// Number of top-level non-nil errors
 | 
			
		||||
	Count int
 | 
			
		||||
 | 
			
		||||
	// Total number of errors including multiErrors
 | 
			
		||||
	Capacity int
 | 
			
		||||
 | 
			
		||||
	// Index of the first non-nil error in the list. Value is meaningless if
 | 
			
		||||
	// Count is zero.
 | 
			
		||||
	FirstErrorIdx int
 | 
			
		||||
 | 
			
		||||
	// Whether the list contains at least one multiError
 | 
			
		||||
	ContainsMultiError bool
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Inspects the given slice of errors so that we can efficiently allocate
 | 
			
		||||
// space for it.
 | 
			
		||||
func inspect(errors []error) (res inspectResult) {
 | 
			
		||||
	first := true
 | 
			
		||||
	for i, err := range errors {
 | 
			
		||||
		if err == nil {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		res.Count++
 | 
			
		||||
		if first {
 | 
			
		||||
			first = false
 | 
			
		||||
			res.FirstErrorIdx = i
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if merr, ok := err.(*multiError); ok {
 | 
			
		||||
			res.Capacity += len(merr.errors)
 | 
			
		||||
			res.ContainsMultiError = true
 | 
			
		||||
		} else {
 | 
			
		||||
			res.Capacity++
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// fromSlice converts the given list of errors into a single error.
 | 
			
		||||
func fromSlice(errors []error) error {
 | 
			
		||||
	res := inspect(errors)
 | 
			
		||||
	switch res.Count {
 | 
			
		||||
	case 0:
 | 
			
		||||
		return nil
 | 
			
		||||
	case 1:
 | 
			
		||||
		// only one non-nil entry
 | 
			
		||||
		return errors[res.FirstErrorIdx]
 | 
			
		||||
	case len(errors):
 | 
			
		||||
		if !res.ContainsMultiError {
 | 
			
		||||
			// already flat
 | 
			
		||||
			return &multiError{errors: errors}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	nonNilErrs := make([]error, 0, res.Capacity)
 | 
			
		||||
	for _, err := range errors[res.FirstErrorIdx:] {
 | 
			
		||||
		if err == nil {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if nested, ok := err.(*multiError); ok {
 | 
			
		||||
			nonNilErrs = append(nonNilErrs, nested.errors...)
 | 
			
		||||
		} else {
 | 
			
		||||
			nonNilErrs = append(nonNilErrs, err)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &multiError{errors: nonNilErrs}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Combine combines the passed errors into a single error.
 | 
			
		||||
//
 | 
			
		||||
// If zero arguments were passed or if all items are nil, a nil error is
 | 
			
		||||
// returned.
 | 
			
		||||
//
 | 
			
		||||
// 	Combine(nil, nil)  // == nil
 | 
			
		||||
//
 | 
			
		||||
// If only a single error was passed, it is returned as-is.
 | 
			
		||||
//
 | 
			
		||||
// 	Combine(err)  // == err
 | 
			
		||||
//
 | 
			
		||||
// Combine skips over nil arguments so this function may be used to combine
 | 
			
		||||
// together errors from operations that fail independently of each other.
 | 
			
		||||
//
 | 
			
		||||
// 	multierr.Combine(
 | 
			
		||||
// 		reader.Close(),
 | 
			
		||||
// 		writer.Close(),
 | 
			
		||||
// 		pipe.Close(),
 | 
			
		||||
// 	)
 | 
			
		||||
//
 | 
			
		||||
// If any of the passed errors is a multierr error, it will be flattened along
 | 
			
		||||
// with the other errors.
 | 
			
		||||
//
 | 
			
		||||
// 	multierr.Combine(multierr.Combine(err1, err2), err3)
 | 
			
		||||
// 	// is the same as
 | 
			
		||||
// 	multierr.Combine(err1, err2, err3)
 | 
			
		||||
//
 | 
			
		||||
// The returned error formats into a readable multi-line error message if
 | 
			
		||||
// formatted with %+v.
 | 
			
		||||
//
 | 
			
		||||
// 	fmt.Sprintf("%+v", multierr.Combine(err1, err2))
 | 
			
		||||
func Combine(errors ...error) error {
 | 
			
		||||
	return fromSlice(errors)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Append appends the given errors together. Either value may be nil.
 | 
			
		||||
//
 | 
			
		||||
// This function is a specialization of Combine for the common case where
 | 
			
		||||
// there are only two errors.
 | 
			
		||||
//
 | 
			
		||||
// 	err = multierr.Append(reader.Close(), writer.Close())
 | 
			
		||||
//
 | 
			
		||||
// The following pattern may also be used to record failure of deferred
 | 
			
		||||
// operations without losing information about the original error.
 | 
			
		||||
//
 | 
			
		||||
// 	func doSomething(..) (err error) {
 | 
			
		||||
// 		f := acquireResource()
 | 
			
		||||
// 		defer func() {
 | 
			
		||||
// 			err = multierr.Append(err, f.Close())
 | 
			
		||||
// 		}()
 | 
			
		||||
func Append(left error, right error) error {
 | 
			
		||||
	switch {
 | 
			
		||||
	case left == nil:
 | 
			
		||||
		return right
 | 
			
		||||
	case right == nil:
 | 
			
		||||
		return left
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if _, ok := right.(*multiError); !ok {
 | 
			
		||||
		if l, ok := left.(*multiError); ok && !l.copyNeeded.Swap(true) {
 | 
			
		||||
			// Common case where the error on the left is constantly being
 | 
			
		||||
			// appended to.
 | 
			
		||||
			errs := append(l.errors, right)
 | 
			
		||||
			return &multiError{errors: errs}
 | 
			
		||||
		} else if !ok {
 | 
			
		||||
			// Both errors are single errors.
 | 
			
		||||
			return &multiError{errors: []error{left, right}}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Either right or both, left and right, are multiErrors. Rely on usual
 | 
			
		||||
	// expensive logic.
 | 
			
		||||
	errors := [2]error{left, right}
 | 
			
		||||
	return fromSlice(errors[0:])
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// AppendInto appends an error into the destination of an error pointer and
 | 
			
		||||
// returns whether the error being appended was non-nil.
 | 
			
		||||
//
 | 
			
		||||
// 	var err error
 | 
			
		||||
// 	multierr.AppendInto(&err, r.Close())
 | 
			
		||||
// 	multierr.AppendInto(&err, w.Close())
 | 
			
		||||
//
 | 
			
		||||
// The above is equivalent to,
 | 
			
		||||
//
 | 
			
		||||
// 	err := multierr.Append(r.Close(), w.Close())
 | 
			
		||||
//
 | 
			
		||||
// As AppendInto reports whether the provided error was non-nil, it may be
 | 
			
		||||
// used to build a multierr error in a loop more ergonomically. For example:
 | 
			
		||||
//
 | 
			
		||||
// 	var err error
 | 
			
		||||
// 	for line := range lines {
 | 
			
		||||
// 		var item Item
 | 
			
		||||
// 		if multierr.AppendInto(&err, parse(line, &item)) {
 | 
			
		||||
// 			continue
 | 
			
		||||
// 		}
 | 
			
		||||
// 		items = append(items, item)
 | 
			
		||||
// 	}
 | 
			
		||||
//
 | 
			
		||||
// Compare this with a verison that relies solely on Append:
 | 
			
		||||
//
 | 
			
		||||
// 	var err error
 | 
			
		||||
// 	for line := range lines {
 | 
			
		||||
// 		var item Item
 | 
			
		||||
// 		if parseErr := parse(line, &item); parseErr != nil {
 | 
			
		||||
// 			err = multierr.Append(err, parseErr)
 | 
			
		||||
// 			continue
 | 
			
		||||
// 		}
 | 
			
		||||
// 		items = append(items, item)
 | 
			
		||||
// 	}
 | 
			
		||||
func AppendInto(into *error, err error) (errored bool) {
 | 
			
		||||
	if into == nil {
 | 
			
		||||
		// We panic if 'into' is nil. This is not documented above
 | 
			
		||||
		// because suggesting that the pointer must be non-nil may
 | 
			
		||||
		// confuse users into thinking that the error that it points
 | 
			
		||||
		// to must be non-nil.
 | 
			
		||||
		panic("misuse of multierr.AppendInto: into pointer must not be nil")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if err == nil {
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
	*into = Append(*into, err)
 | 
			
		||||
	return true
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										8
									
								
								vendor/go.uber.org/multierr/glide.yaml
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								vendor/go.uber.org/multierr/glide.yaml
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
package: go.uber.org/multierr
 | 
			
		||||
import:
 | 
			
		||||
- package: go.uber.org/atomic
 | 
			
		||||
  version: ^1
 | 
			
		||||
testImport:
 | 
			
		||||
- package: github.com/stretchr/testify
 | 
			
		||||
  subpackages:
 | 
			
		||||
  - assert
 | 
			
		||||
							
								
								
									
										52
									
								
								vendor/go.uber.org/multierr/go113.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								vendor/go.uber.org/multierr/go113.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,52 @@
 | 
			
		||||
// Copyright (c) 2019 Uber Technologies, Inc.
 | 
			
		||||
//
 | 
			
		||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
			
		||||
// of this software and associated documentation files (the "Software"), to deal
 | 
			
		||||
// in the Software without restriction, including without limitation the rights
 | 
			
		||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
			
		||||
// copies of the Software, and to permit persons to whom the Software is
 | 
			
		||||
// furnished to do so, subject to the following conditions:
 | 
			
		||||
//
 | 
			
		||||
// The above copyright notice and this permission notice shall be included in
 | 
			
		||||
// all copies or substantial portions of the Software.
 | 
			
		||||
//
 | 
			
		||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
			
		||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
			
		||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
			
		||||
// THE SOFTWARE.
 | 
			
		||||
 | 
			
		||||
// +build go1.13
 | 
			
		||||
 | 
			
		||||
package multierr
 | 
			
		||||
 | 
			
		||||
import "errors"
 | 
			
		||||
 | 
			
		||||
// As attempts to find the first error in the error list that matches the type
 | 
			
		||||
// of the value that target points to.
 | 
			
		||||
//
 | 
			
		||||
// This function allows errors.As to traverse the values stored on the
 | 
			
		||||
// multierr error.
 | 
			
		||||
func (merr *multiError) As(target interface{}) bool {
 | 
			
		||||
	for _, err := range merr.Errors() {
 | 
			
		||||
		if errors.As(err, target) {
 | 
			
		||||
			return true
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return false
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Is attempts to match the provided error against errors in the error list.
 | 
			
		||||
//
 | 
			
		||||
// This function allows errors.Is to traverse the values stored on the
 | 
			
		||||
// multierr error.
 | 
			
		||||
func (merr *multiError) Is(target error) bool {
 | 
			
		||||
	for _, err := range merr.Errors() {
 | 
			
		||||
		if errors.Is(err, target) {
 | 
			
		||||
			return true
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return false
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user