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

Side by Side Diff: common/errors/annotate_example_test.go

Issue 2958433002: [errors] Remove Fix(), move MultiErrorFromErrors(). (Closed)
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « no previous file | common/errors/multierror.go » ('j') | common/sync/parallel/workPool.go » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package errors 5 package errors
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 ) 9 )
10 10
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 } 43 }
44 return err 44 return err
45 } 45 }
46 46
47 func someIntermediateFunc(vals ...int) error { 47 func someIntermediateFunc(vals ...int) error {
48 errch := make(chan error) 48 errch := make(chan error)
49 go func() { 49 go func() {
50 defer close(errch) 50 defer close(errch)
51 errch <- Annotate(errorWrapper(someLibFunc(vals...))).Reason("co uld not process").Err() 51 errch <- Annotate(errorWrapper(someLibFunc(vals...))).Reason("co uld not process").Err()
52 }() 52 }()
53 » if err := MultiErrorFromErrors(errch); err != nil { 53 » me := MultiError(nil)
54 » » return Annotate(err).Reason("while processing %(vals)v").D("vals ", vals).Err() 54 » for err := range errch {
55 » » if err != nil {
56 » » » me = append(me, err)
57 » » }
58 » }
59 » if me != nil {
60 » » return Annotate(me).Reason("while processing %(vals)v").D("vals" , vals).Err()
55 } 61 }
56 return nil 62 return nil
57 } 63 }
58 64
59 func ExampleAnnotate() { 65 func ExampleAnnotate() {
60 if err := someIntermediateFunc(3); err != nil { 66 if err := someIntermediateFunc(3); err != nil {
61 err = Annotate(err).Reason("top level").Err() 67 err = Annotate(err).Reason("top level").Err()
62 fmt.Println("Public-facing error:\n ", err) 68 fmt.Println("Public-facing error:\n ", err)
63 fmt.Println("\nfull error:") 69 fmt.Println("\nfull error:")
64 for _, l := range FixForTest(RenderStack(err).ToLines("runtime", "_test")) { 70 for _, l := range FixForTest(RenderStack(err).ToLines("runtime", "_test")) {
(...skipping 30 matching lines...) Expand all
95 // MultiError 1/1: following first non-nil error. 101 // MultiError 1/1: following first non-nil error.
96 // "non-nil" = 1 102 // "non-nil" = 1
97 // "total" = 1 103 // "total" = 1
98 // 104 //
99 // #? github.com/luci/luci-go/common/errors/annotate_example_test.go:51 - errors.someIntermediateFunc.func1() 105 // #? github.com/luci/luci-go/common/errors/annotate_example_test.go:51 - errors.someIntermediateFunc.func1()
100 // reason: "could not process" 106 // reason: "could not process"
101 // 107 //
102 // ... skipped SOME frames in pkg "runtime"... 108 // ... skipped SOME frames in pkg "runtime"...
103 // 109 //
104 // GOROUTINE LINE 110 // GOROUTINE LINE
105 » // #? github.com/luci/luci-go/common/errors/annotate_example_test.go:54 - errors.someIntermediateFunc() 111 » // #? github.com/luci/luci-go/common/errors/annotate_example_test.go:60 - errors.someIntermediateFunc()
106 // reason: "while processing [3]" 112 // reason: "while processing [3]"
107 // "vals" = []int{3} 113 // "vals" = []int{3}
108 // 114 //
109 » // #? github.com/luci/luci-go/common/errors/annotate_example_test.go:60 - errors.ExampleAnnotate() 115 » // #? github.com/luci/luci-go/common/errors/annotate_example_test.go:66 - errors.ExampleAnnotate()
110 // reason: "top level" 116 // reason: "top level"
111 // 117 //
112 // #? testing/example.go:XXX - testing.runExample() 118 // #? testing/example.go:XXX - testing.runExample()
113 // #? testing/example.go:XXX - testing.runExamples() 119 // #? testing/example.go:XXX - testing.runExamples()
114 // #? testing/testing.go:XXX - testing.(*M).Run() 120 // #? testing/testing.go:XXX - testing.(*M).Run()
115 // ... skipped SOME frames in pkg "_test"... 121 // ... skipped SOME frames in pkg "_test"...
116 // ... skipped SOME frames in pkg "runtime"... 122 // ... skipped SOME frames in pkg "runtime"...
117
118 } 123 }
OLDNEW
« no previous file with comments | « no previous file | common/errors/multierror.go » ('j') | common/sync/parallel/workPool.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698