From 638efef8149304e99fa86e838f307e3610533859 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 29 Sep 2015 10:18:31 -0700 Subject: [PATCH] Update to new version of probe --- vendor.json | 8 +-- .../github.com/minio/minio/pkg/probe/probe.go | 54 +++++++++++++------ 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/vendor.json b/vendor.json index 77608e8e..7563dffc 100755 --- a/vendor.json +++ b/vendor.json @@ -55,15 +55,15 @@ "canonical": "github.com/minio/minio/pkg/probe", "comment": "", "local": "vendor/github.com/minio/minio/pkg/probe", - "revision": "2f260adc69701f89a38fc8a27cde4b868dfe9ddf", - "revisionTime": "2015-08-24T03:43:13-07:00" + "revision": "daa089fb06b05ad7a9ce945e51362d349ffaf662", + "revisionTime": "2015-09-29T10:17:19-07:00" }, { "canonical": "github.com/minio/minio/pkg/quick", "comment": "", "local": "vendor/github.com/minio/minio/pkg/quick", - "revision": "4d1f38d28cabcfa321e9d88acef67e16e7bafb2a", - "revisionTime": "2015-08-22T18:37:56-07:00" + "revision": "daa089fb06b05ad7a9ce945e51362d349ffaf662", + "revisionTime": "2015-09-29T10:17:19-07:00" }, { "canonical": "github.com/minio/pb", diff --git a/vendor/github.com/minio/minio/pkg/probe/probe.go b/vendor/github.com/minio/minio/pkg/probe/probe.go index 5a30c319..c82df6bd 100644 --- a/vendor/github.com/minio/minio/pkg/probe/probe.go +++ b/vendor/github.com/minio/minio/pkg/probe/probe.go @@ -50,11 +50,12 @@ func GetSysInfo() map[string]string { } } +// TracePoint container for individual trace entries in overall call trace type TracePoint struct { - Line int `json:"Line,omitempty"` - Filename string `json:"File,omitempty"` - Function string `json:"Func,omitempty"` - Env map[string][]string `json:"Env,omitempty"` + Line int `json:"line,omitempty"` + Filename string `json:"file,omitempty"` + Function string `json:"func,omitempty"` + Env map[string][]string `json:"env,omitempty"` } // Error implements tracing error functionality. @@ -65,10 +66,24 @@ type Error struct { SysInfo map[string]string `json:"sysinfo,omitempty"` } -// NewError function instantiates an error probe for tracing. Original errors.error (golang's error -// interface) is injected in only once during this New call. Rest of the time, you -// trace the return path with Probe.Trace and finally handle reporting or quitting -// at the top level. +// NewError function instantiates an error probe for tracing. +// Default ``error`` (golang's error interface) is injected in +// only once. Rest of the time, you trace the return path with +// ``probe.Trace`` and finally handling them at top level +// +// Following dummy code talks about how one can pass up the +// errors and put them in CallTrace. +// +// func sendError() *probe.Error { +// return probe.NewError(errors.New("Help Needed")) +// } +// func recvError() *probe.Error { +// return sendError().Trace() +// } +// if err := recvError(); err != nil { +// log.Fatalln(err.Trace()) +// } +// func NewError(e error) *Error { if e == nil { return nil @@ -77,8 +92,8 @@ func NewError(e error) *Error { return Err.trace() } -// Trace records the point at which it is invoked. Stack traces are important for -// debugging purposes. +// Trace records the point at which it is invoked. +// Stack traces are important for debugging purposes. func (e *Error) Trace(fields ...string) *Error { if e == nil { return nil @@ -90,9 +105,11 @@ func (e *Error) Trace(fields ...string) *Error { return e.trace(fields...) } -// internal trace - records the point at which it is invoked. Stack traces are important for -// debugging purposes. +// Internal trace - records the point at which it is invoked. func (e *Error) trace(fields ...string) *Error { + if e == nil { + return nil + } pc, file, line, _ := runtime.Caller(2) function := runtime.FuncForPC(pc).Name() _, function = filepath.Split(function) @@ -107,7 +124,7 @@ func (e *Error) trace(fields ...string) *Error { return e } -// Untrace erases last trace entry. +// Untrace erases last known trace entry. func (e *Error) Untrace() *Error { if e == nil { return nil @@ -125,6 +142,9 @@ func (e *Error) Untrace() *Error { // ToGoError returns original error message. func (e *Error) ToGoError() error { + if e == nil || e.Cause == nil { + return nil + } return e.Cause } @@ -137,19 +157,19 @@ func (e *Error) String() string { defer e.lock.RUnlock() if e.Cause != nil { - str := e.Cause.Error() + "\n" + str := e.Cause.Error() callLen := len(e.CallTrace) for i := callLen - 1; i >= 0; i-- { if len(e.CallTrace[i].Env) > 0 { - str += fmt.Sprintf(" (%d) %s:%d %s(..) Tags: [%s]\n", + str += fmt.Sprintf("\n (%d) %s:%d %s(..) Tags: [%s]", i, e.CallTrace[i].Filename, e.CallTrace[i].Line, e.CallTrace[i].Function, strings.Join(e.CallTrace[i].Env["Tags"], ", ")) } else { - str += fmt.Sprintf(" (%d) %s:%d %s(..)\n", + str += fmt.Sprintf("\n (%d) %s:%d %s(..)", i, e.CallTrace[i].Filename, e.CallTrace[i].Line, e.CallTrace[i].Function) } } - str += " Host:" + e.SysInfo["host.name"] + " | " + str += "\n" + " Host:" + e.SysInfo["host.name"] + " | " str += "OS:" + e.SysInfo["host.os"] + " | " str += "Arch:" + e.SysInfo["host.arch"] + " | " str += "Lang:" + e.SysInfo["host.lang"] + " | "