error handling updates
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
|
||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
||||
@@ -29,7 +30,22 @@ func fatalIf(err *probe.Error) {
|
||||
return
|
||||
}
|
||||
if globalJSONFlag {
|
||||
console.Println(ErrorMessage{err})
|
||||
errorMessage := struct {
|
||||
// Error string `json:"error"`
|
||||
Cause error `json:"cause"`
|
||||
Type string `json:"type"`
|
||||
CallTrace []probe.TracePoint `json:"trace,omitempty"`
|
||||
SysInfo map[string]string `json:"sysinfo"`
|
||||
}{
|
||||
Type: "Fatal",
|
||||
Cause: err.ToGoError(),
|
||||
SysInfo: err.SysInfo,
|
||||
}
|
||||
if globalDebugFlag {
|
||||
errorMessage.CallTrace = err.CallTrace
|
||||
}
|
||||
json, _ := json.Marshal(errorMessage)
|
||||
console.Println(string(json))
|
||||
os.Exit(1)
|
||||
}
|
||||
if !globalDebugFlag {
|
||||
@@ -44,13 +60,26 @@ func errorIf(err *probe.Error) {
|
||||
return
|
||||
}
|
||||
if globalJSONFlag {
|
||||
errorMessage := ErrorMessage{err}
|
||||
console.Println(errorMessage)
|
||||
errorMessage := struct {
|
||||
// Error string `json:"error"`
|
||||
Cause error `json:"cause"`
|
||||
Type string `json:"type"`
|
||||
CallTrace []probe.TracePoint `json:"trace,omitempty"`
|
||||
SysInfo map[string]string `json:"sysinfo"`
|
||||
}{
|
||||
Type: "Error",
|
||||
Cause: err.ToGoError(),
|
||||
SysInfo: err.SysInfo,
|
||||
}
|
||||
if globalDebugFlag {
|
||||
errorMessage.CallTrace = err.CallTrace
|
||||
}
|
||||
json, _ := json.Marshal(errorMessage)
|
||||
console.Println(string(json))
|
||||
return
|
||||
}
|
||||
if !globalDebugFlag {
|
||||
console.Errorln(err.ToGoError())
|
||||
return
|
||||
}
|
||||
console.Errorln(err)
|
||||
}
|
||||
|
||||
@@ -50,18 +50,18 @@ func GetSysInfo() map[string]string {
|
||||
}
|
||||
}
|
||||
|
||||
type tracePoint struct {
|
||||
Line int `json:"Line"`
|
||||
Filename string `json:"File"`
|
||||
Function string `json:"Func"`
|
||||
Env map[string][]string `json:"Env"`
|
||||
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"`
|
||||
}
|
||||
|
||||
// Error implements tracing error functionality.
|
||||
type Error struct {
|
||||
lock sync.RWMutex
|
||||
Cause error `json:"cause,omitempty"`
|
||||
CallTrace []tracePoint `json:"trace,omitempty"`
|
||||
CallTrace []TracePoint `json:"trace,omitempty"`
|
||||
SysInfo map[string]string `json:"sysinfo,omitempty"`
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ func NewError(e error) *Error {
|
||||
if e == nil {
|
||||
return nil
|
||||
}
|
||||
Err := Error{lock: sync.RWMutex{}, Cause: e, CallTrace: []tracePoint{}, SysInfo: GetSysInfo()}
|
||||
Err := Error{lock: sync.RWMutex{}, Cause: e, CallTrace: []TracePoint{}, SysInfo: GetSysInfo()}
|
||||
return Err.trace()
|
||||
}
|
||||
|
||||
@@ -97,11 +97,11 @@ func (e *Error) trace(fields ...string) *Error {
|
||||
function := runtime.FuncForPC(pc).Name()
|
||||
_, function = filepath.Split(function)
|
||||
file = "..." + strings.TrimPrefix(file, os.Getenv("GOPATH")) // trim gopathSource from file
|
||||
tp := tracePoint{}
|
||||
tp := TracePoint{}
|
||||
if len(fields) > 0 {
|
||||
tp = tracePoint{Line: line, Filename: file, Function: function, Env: map[string][]string{"Tags": fields}}
|
||||
tp = TracePoint{Line: line, Filename: file, Function: function, Env: map[string][]string{"Tags": fields}}
|
||||
} else {
|
||||
tp = tracePoint{Line: line, Filename: file, Function: function}
|
||||
tp = TracePoint{Line: line, Filename: file, Function: function}
|
||||
}
|
||||
e.CallTrace = append(e.CallTrace, tp)
|
||||
return e
|
||||
|
||||
@@ -48,8 +48,8 @@
|
||||
"canonical": "github.com/minio/minio/pkg/probe",
|
||||
"comment": "",
|
||||
"local": "github.com/minio/minio/pkg/probe",
|
||||
"revision": "8789c5a49d3212d38ee42b36eec6eaeea45d6778",
|
||||
"revisionTime": "2015-08-18T23:52:04-07:00"
|
||||
"revision": "f223c8b36d4553962dd6a0ab587f2db82dc367f7",
|
||||
"revisionTime": "2015-08-19T01:23:59-07:00"
|
||||
},
|
||||
{
|
||||
"canonical": "github.com/minio/minio/pkg/quick",
|
||||
|
||||
@@ -24,35 +24,9 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
)
|
||||
|
||||
// ErrorMessage json container for error messages
|
||||
type ErrorMessage struct {
|
||||
*probe.Error
|
||||
}
|
||||
|
||||
func (e ErrorMessage) String() string {
|
||||
if !globalJSONFlag {
|
||||
return e.Cause.Error()
|
||||
}
|
||||
if !globalDebugFlag {
|
||||
errorMessageBytes, err := json.MarshalIndent(struct {
|
||||
Cause error `json:"cause"`
|
||||
}{Cause: e.Cause}, "", "\t")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return console.JSON(string(errorMessageBytes) + "\n")
|
||||
}
|
||||
errorMessageBytes, err := json.MarshalIndent(e, "", "\t")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return console.JSON(string(errorMessageBytes) + "\n")
|
||||
}
|
||||
|
||||
// DiffJSONMessage json container for diff messages
|
||||
type DiffJSONMessage struct {
|
||||
FirstURL string `json:"first"`
|
||||
|
||||
Reference in New Issue
Block a user