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

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

Issue 1249933002: Move multierror logic into luci-go. (Closed) Base URL: https://github.com/luci/luci-go@add_mathrand
Patch Set: rename Created 5 years, 5 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
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package errors
6
7 import (
8 "fmt"
9 "path/filepath"
10 "runtime"
11 )
12
13 // MarkedError is the specific error type retuned by MakeMarkFn. It's designed
14 // so that you can access the underlying object if needed.
15 type MarkedError struct {
16 // Orig contains the original data (error or otherwise) which was passed to
17 // the marker function.
18 Orig interface{}
19
20 msgFmt string
21 }
22
23 func (te *MarkedError) Error() string {
24 return fmt.Sprintf(te.msgFmt, te.Orig)
25 }
26
27 // MakeMarkFn returns a new 'marker' function for your library. The name paramet er
28 // should probably match your package name, but it can by any string which
29 // will help identify the error as originating from your package.
30 func MakeMarkFn(name string) func(interface{}) error {
31 fmtstring1 := name + " - %s:%d - %%+v"
32 fmtstring2 := name + " - %+v"
33 return func(errish interface{}) error {
34 if errish == nil {
35 return nil
36 }
37 _, filename, line, gotInfo := runtime.Caller(1)
38 pfx := fmtstring2
39 if gotInfo {
40 pfx = fmt.Sprintf(fmtstring1, filepath.Base(filename), l ine)
41 }
42 return &MarkedError{errish, pfx}
43 }
44 }
OLDNEW
« no previous file with comments | « common/errors/doc.go ('k') | common/errors/errors_test.go » ('j') | common/errors/multierror.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698