Skip to content

Commit

Permalink
Cleanup. Remove unused functions.
Browse files Browse the repository at this point in the history
Clarify README.md documentation.
  • Loading branch information
mspiegel committed Nov 23, 2017
1 parent 065aa64 commit dd14681
Show file tree
Hide file tree
Showing 10 changed files with 9 additions and 814 deletions.
45 changes: 9 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -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`.

Expand All @@ -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

Expand All @@ -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
```
Expand Down Expand Up @@ -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()
```
```
15 changes: 0 additions & 15 deletions multierror.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
14 changes: 0 additions & 14 deletions multierror_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
37 changes: 0 additions & 37 deletions prefix.go

This file was deleted.

33 changes: 0 additions & 33 deletions prefix_test.go

This file was deleted.

54 changes: 0 additions & 54 deletions scripts/deps.sh

This file was deleted.

0 comments on commit dd14681

Please sign in to comment.