~rogpeppe/goose/state-of-the-world

« back to all changes in this revision

Viewing changes to errors/errors.go

  • Committer: Ian Booth
  • Date: 2012-11-21 07:56:19 UTC
  • Revision ID: ian.booth@canonical.com-20121121075619-4fh6i9yq6fj6cwct
Extract identity functionality from client, and also extract common HTTP methods

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Utility functions for reporting errors.
 
2
 
 
3
package errors
 
4
 
 
5
import (
 
6
        "errors"
 
7
        "fmt"
 
8
)
 
9
 
 
10
// AddErrorContext prefixes any error stored in err with text formatted
 
11
// according to the format specifier. If err does not contain an error,
 
12
// AddErrorContext does nothing.
 
13
func AddErrorContext(err *error, format string, args ...interface{}) {
 
14
        if *err != nil {
 
15
                *err = errors.New(fmt.Sprintf(format, args...) + ": " + (*err).Error())
 
16
        }
 
17
}
 
18