| commit | 585415ced4abef0b0ceff6c495690df98db83abb | [log] [tgz] |
|---|---|---|
| author | iannucci <iannucci@chromium.org> | Wed Jun 28 18:13:14 2017 |
| committer | Commit Bot <commit-bot@chromium.org> | Wed Jun 28 18:13:14 2017 |
| tree | 5d51e928ecb18f1853f998b1ace5a9f37109d257 | |
| parent | 2ae56cd555233728c302e9a67d229fc35aaf007f [diff] |
[errors] de-specialize Transient in favor of Tags.
Previously 'transience' was a hard-coded attribute of the errors package. This
change adds 'tags' as a way to put attributes (potentially with some data) onto an
error as it goes up the stack.
This removes multiple symbols from the errors package (the stack context stuff
is now an implementation detail, tags are better than ExtractData).
The 'transience' bit has now moved to the 'common/retry/transient' package.
Marking an error as transient is now `err = transient.Tag.Apply(err)`, or
`errors.Annotate(err).Tag(transient.Tag).Err()` (as part of another batch
of annotations).
API Review in a Nutshell:
// for simple 'boolean' tags, where presence is the only important piece of
// information.
var FatalTag = errors.BoolTag{errors.NewTagKey("this is a fatal error!")}
func (...) error {
return FatalTag.Apply(err)
}
func (...) {
if FatalTag.In(err) {
os.Exit(-1)
}
}
// tags may also have associated typesafe values
type Severity int
type severityTagType struct {Key errors.TagKey}
func (t severityTagType) With(s Severity) errors.TagValue { return errors.MkTagValue(t.Key, s) }
func (t severityTagType) In(err error) (s Severity, ok bool) {
d, ok := errors.TagValueIn(t.Key, err)
if ok {
s = d.(Severity)
}
return
}
var SeverityTag = severityTagType{errors.NewTagKey("holds a Severity value")}
func (...) error {
return SeverityTag.With(Severity(10)).Apply(err)
}
func (...) {
if s, hasSeverity := SeverityTag.In(err); hasSeverity {
if s.(Severity) > 9000 {
fmt.Println("it's pretty severe")
}
}
}
BUG=
Review-Url: https://codereview.chromium.org/2951393002
go get -u github.com/luci/luci-go/client/cmd/... go get -u github.com/luci/luci-go/server/cmd/...
/common/... and /server/..../appengine/..., /client/... and /server/...; for example, the structures used by the server APIs. These are inherently APIs./appengine/....go1 contains the stable code.master constains the latest code.user.email and user.name are configured in git config.go get -u -t github.com/luci/luci-go/client/...go get -u github.com/maruel/pre-commit-go/cmd/... && pcgRun the following to setup the code review tool and create your first review:
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git $HOME/src/depot_tools export PATH="$PATH:$HOME/src/depot_tools" cd $GOROOT/github.com/luci/luci-go git checkout -b work origin/master # hack hack git commit -a -m "This is awesome\nR=joe@example.com" # This will ask for your Google Account credentials. git cl upload -s # Wait for LGTM over email. # Check the commit queue box in codereview website. # Wait for the change to be tested and landed automatically.
Use git cl help and git cl help <cmd> for more details.