2648
|
|
[r=dimitern] errors: Improve tests, unify interfaces, wrapping
The errors package is refactored so that for all errors defined there are 3 functions with consistent names: * Is<type>(error) bool Returns true if the error satifies <type> (i.e. it was created with one of the two constructors below for <type>. * New<type>(error, string) error Creates an error of <type> wrapping the given error and adding the prefix to the message. * <type>f(string, ...interface{}) error Creates an error of <type> with a message, formatted like fmt.Sprintf.
Dropped "Error" from type and function names (as they already are in the "errors" package). Moved utils.ErrorContextf in here, renaming it to Maskf. A new helper called Contextf is added, which works similarly to Maskf, but preserves the original error when wrapping (if it's one of the known types), so that the Is<type>() satifiers will work on the wrapped error as well.
Added automatic exhaustive testing for each error type in a way that makes it easier to add new types.
Few drive-by fixes made while fixing the rest of the code base to use the new function names.
I realize we should use errgo for such things, but we can easily change the errors package to use errgo internally later.
https://codereview.appspot.com/87560043/
R=rogpeppe
|
Dimiter Naydenov |
|
10 years ago
|
|
|
2567
|
|
|
Dimiter Naydenov |
|
10 years ago
|
|
|
2473
|
|
|
Dimiter Naydenov |
|
10 years ago
|
|
|
2459
|
|
|
Bodie Solomon |
juju-1.17.6 |
10 years ago
|
|
|
2356
|
|
|
Curtis Hovey |
|
10 years ago
|
|
|
2131
|
|
|
Andrew Wilkins |
|
10 years ago
|
|
|
2129
|
|
|
William Reade |
|
10 years ago
|
|
|
2099
|
|
|
Curtis Hovey |
|
10 years ago
|
|
|
2045
|
|
|
William Reade |
|
10 years ago
|
|
|