Skip to content

Instantly share code, notes, and snippets.

@jnericks
Created August 16, 2016 22:21
Show Gist options
  • Save jnericks/388d5693262f5b313b51fa4d1195fa2c to your computer and use it in GitHub Desktop.
Save jnericks/388d5693262f5b313b51fa4d1195fa2c to your computer and use it in GitHub Desktop.

Revisions

  1. jnericks created this gist Aug 16, 2016.
    18 changes: 18 additions & 0 deletions errors.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    package main

    import "fmt"

    // Errors allows you to compose multiple errors
    type Errors []error

    func (e Errors) Error() string {
    if len(e) == 1 {
    return e[0].Error()
    }

    msg := "multiple errors:"
    for i, err := range e {
    msg = fmt.Sprintf("%s\n\t%2d: %s", msg, i, err.Error())
    }
    return msg
    }