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

Side by Side Diff: go/src/infra/libs/errors/errors.go

Issue 1153883002: go: infra/libs/* now live in luci-go. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: move the rest too Created 5 years, 7 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 | « go/src/infra/libs/bit_field/bf_test.go ('k') | go/src/infra/libs/errors/errors_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 | « go/src/infra/libs/bit_field/bf_test.go ('k') | go/src/infra/libs/errors/errors_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698