Updating iodine

master
Frederick F. Kautz IV 10 years ago
parent 938a0fa4a9
commit 2acd66ae96
  1. 2
      Godeps/Godeps.json
  2. 13
      Godeps/_workspace/src/github.com/minio-io/iodine/iodine.go
  3. 2
      Godeps/_workspace/src/github.com/minio-io/iodine/iodine_test.go

2
Godeps/Godeps.json generated vendored

@ -20,7 +20,7 @@
}, },
{ {
"ImportPath": "github.com/minio-io/iodine", "ImportPath": "github.com/minio-io/iodine",
"Rev": "3d54fa6339544392a0eaadcf2692fbc94d4ac21d" "Rev": "f2dbd51c3b4f8530a9b8e2dbc32788175df2fa5c"
}, },
{ {
"ImportPath": "gopkg.in/check.v1", "ImportPath": "gopkg.in/check.v1",

@ -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()
} }

@ -32,7 +32,7 @@ func TestIodine(t *testing.T) {
if len(iodineError.Stack) != 4 { if len(iodineError.Stack) != 4 {
t.Fail() t.Fail()
} }
jsonResult, err := iodineError.EmitJson() jsonResult, err := iodineError.EmitJSON()
if err != nil { if err != nil {
t.Fail() t.Fail()
} }

Loading…
Cancel
Save