Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Unified Diff: common/errors/annotate_example_test.go

Issue 2963503003: [errors] Greatly simplify common/errors package. (Closed)
Patch Set: fix nits Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « common/errors/annotate.go ('k') | common/errors/annotate_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: common/errors/annotate_example_test.go
diff --git a/common/errors/annotate_example_test.go b/common/errors/annotate_example_test.go
index 58ee286c2b573d2f982751630daf2fec2774669f..13b5490a82740054b17779173f2e062c2bd368d6 100644
--- a/common/errors/annotate_example_test.go
+++ b/common/errors/annotate_example_test.go
@@ -11,11 +11,11 @@ import (
func someProcessingFunction(val int) error {
if val == 1 {
// New and Reason automatically include stack information.
- return Reason("bad number: %(val)d").D("val", val).Err()
+ return Reason("bad number: %d", val).Err()
}
if err := someProcessingFunction(val - 1); err != nil {
// correctly handles recursion
- return Annotate(err).D("val", val).Err()
+ return Annotate(err, "").InternalReason("val(%d)", val).Err()
}
return nil
}
@@ -23,10 +23,8 @@ func someProcessingFunction(val int) error {
func someLibFunc(vals ...int) error {
for i, v := range vals {
if err := someProcessingFunction(v); err != nil {
- return (Annotate(err).Reason("processing %(val)d").
- D("val", v).
- D("i", i).
- D("secret", "value", "%s").Err())
+ return Annotate(err, "processing %d", v).
+ InternalReason("secret(%s)/i(%d)", "value", i).Err()
}
}
return nil
@@ -48,7 +46,7 @@ func someIntermediateFunc(vals ...int) error {
errch := make(chan error)
go func() {
defer close(errch)
- errch <- Annotate(errorWrapper(someLibFunc(vals...))).Reason("could not process").Err()
+ errch <- Annotate(errorWrapper(someLibFunc(vals...)), "could not process").Err()
}()
me := MultiError(nil)
for err := range errch {
@@ -57,17 +55,17 @@ func someIntermediateFunc(vals ...int) error {
}
}
if me != nil {
- return Annotate(me).Reason("while processing %(vals)v").D("vals", vals).Err()
+ return Annotate(me, "while processing %v", vals).Err()
}
return nil
}
func ExampleAnnotate() {
if err := someIntermediateFunc(3); err != nil {
- err = Annotate(err).Reason("top level").Err()
+ err = Annotate(err, "top level").Err()
fmt.Println("Public-facing error:\n ", err)
fmt.Println("\nfull error:")
- for _, l := range FixForTest(RenderStack(err).ToLines("runtime", "_test")) {
+ for _, l := range FixForTest(RenderStack(err, "runtime", "_test")) {
fmt.Println(l)
}
}
@@ -79,41 +77,35 @@ func ExampleAnnotate() {
// full error:
// GOROUTINE LINE
// #? github.com/luci/luci-go/common/errors/annotate_example_test.go:14 - errors.someProcessingFunction()
- // reason: "bad number: 1"
- // "val" = 1
+ // reason: bad number: 1
//
// #? github.com/luci/luci-go/common/errors/annotate_example_test.go:16 - errors.someProcessingFunction()
- // "val" = 2
+ // internal reason: val(2)
//
// #? github.com/luci/luci-go/common/errors/annotate_example_test.go:16 - errors.someProcessingFunction()
- // "val" = 3
+ // internal reason: val(3)
//
// From frame 2 to 3, the following wrappers were found:
// unknown wrapper *errors.MiscWrappedError
//
// #? github.com/luci/luci-go/common/errors/annotate_example_test.go:25 - errors.someLibFunc()
- // reason: "processing 3"
- // "i" = 0
- // "secret" = value
- // "val" = 3
+ // reason: processing 3
+ // internal reason: secret(value)/i(0)
//
// From frame 3 to 4, the following wrappers were found:
- // MultiError 1/1: following first non-nil error.
- // "non-nil" = 1
- // "total" = 1
+ // internal reason: MultiError 1/1: following first non-nil error.
//
- // #? github.com/luci/luci-go/common/errors/annotate_example_test.go:51 - errors.someIntermediateFunc.func1()
- // reason: "could not process"
+ // #? github.com/luci/luci-go/common/errors/annotate_example_test.go:49 - errors.someIntermediateFunc.func1()
+ // reason: could not process
//
// ... skipped SOME frames in pkg "runtime"...
//
// GOROUTINE LINE
- // #? github.com/luci/luci-go/common/errors/annotate_example_test.go:60 - errors.someIntermediateFunc()
- // reason: "while processing [3]"
- // "vals" = []int{3}
+ // #? github.com/luci/luci-go/common/errors/annotate_example_test.go:58 - errors.someIntermediateFunc()
+ // reason: while processing [3]
//
- // #? github.com/luci/luci-go/common/errors/annotate_example_test.go:66 - errors.ExampleAnnotate()
- // reason: "top level"
+ // #? github.com/luci/luci-go/common/errors/annotate_example_test.go:64 - errors.ExampleAnnotate()
+ // reason: top level
//
// #? testing/example.go:XXX - testing.runExample()
// #? testing/example.go:XXX - testing.runExamples()
« no previous file with comments | « common/errors/annotate.go ('k') | common/errors/annotate_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698