|
|
@ -25,6 +25,8 @@ import ( |
|
|
|
"strconv" |
|
|
|
"strconv" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Error is the iodine error which contains a pointer to the original error
|
|
|
|
|
|
|
|
// and stack traces.
|
|
|
|
type Error struct { |
|
|
|
type Error struct { |
|
|
|
EmbeddedError error `json:"-"` |
|
|
|
EmbeddedError error `json:"-"` |
|
|
|
ErrorMessage string |
|
|
|
ErrorMessage string |
|
|
@ -32,6 +34,7 @@ type Error struct { |
|
|
|
Stack []StackEntry |
|
|
|
Stack []StackEntry |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// StackEntry contains the entry in the stack trace
|
|
|
|
type StackEntry struct { |
|
|
|
type StackEntry struct { |
|
|
|
Host string |
|
|
|
Host string |
|
|
|
File string |
|
|
|
File string |
|
|
@ -39,6 +42,8 @@ type StackEntry struct { |
|
|
|
Data map[string]string |
|
|
|
Data map[string]string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Wrap an error, turning it into an iodine error.
|
|
|
|
|
|
|
|
// Adds an initial stack trace.
|
|
|
|
func Wrap(err error, data map[string]string) *Error { |
|
|
|
func Wrap(err error, data map[string]string) *Error { |
|
|
|
entry := createStackEntry() |
|
|
|
entry := createStackEntry() |
|
|
|
for k, v := range data { |
|
|
|
for k, v := range data { |
|
|
@ -63,22 +68,23 @@ func createStackEntry() StackEntry { |
|
|
|
return entry |
|
|
|
return entry |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Annotate an error with a stack entry and returns itself
|
|
|
|
func (err *Error) Annotate(info map[string]string) *Error { |
|
|
|
func (err *Error) Annotate(info map[string]string) *Error { |
|
|
|
data := make(map[string]string) |
|
|
|
data := make(map[string]string) |
|
|
|
if info != nil { |
|
|
|
for k, v := range info { |
|
|
|
for k, v := range info { |
|
|
|
data[k] = v |
|
|
|
data[k] = v |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
entry := createStackEntry() |
|
|
|
entry := createStackEntry() |
|
|
|
err.Stack = append(err.Stack, entry) |
|
|
|
err.Stack = append(err.Stack, entry) |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (err Error) EmitJson() ([]byte, error) { |
|
|
|
// EmitJSON writes JSON output for the error
|
|
|
|
|
|
|
|
func (err Error) EmitJSON() ([]byte, error) { |
|
|
|
return json.Marshal(err) |
|
|
|
return json.Marshal(err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// EmitHumanReadable returns a human readable error message
|
|
|
|
func (err Error) EmitHumanReadable() string { |
|
|
|
func (err Error) EmitHumanReadable() string { |
|
|
|
var errorBuffer bytes.Buffer |
|
|
|
var errorBuffer bytes.Buffer |
|
|
|
fmt.Fprintln(&errorBuffer, err.Error()) |
|
|
|
fmt.Fprintln(&errorBuffer, err.Error()) |
|
|
@ -88,6 +94,7 @@ func (err Error) EmitHumanReadable() string { |
|
|
|
return string(errorBuffer.Bytes()) |
|
|
|
return string(errorBuffer.Bytes()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Emits the original error message
|
|
|
|
func (err Error) Error() string { |
|
|
|
func (err Error) Error() string { |
|
|
|
return err.EmbeddedError.Error() |
|
|
|
return err.EmbeddedError.Error() |
|
|
|
} |
|
|
|
} |
|
|
|