From 2acd66ae9646ba479548827b553541262830499e Mon Sep 17 00:00:00 2001 From: "Frederick F. Kautz IV" Date: Wed, 25 Mar 2015 00:17:50 -0700 Subject: [PATCH] Updating iodine --- Godeps/Godeps.json | 2 +- .../src/github.com/minio-io/iodine/iodine.go | 17 ++++++++++++----- .../github.com/minio-io/iodine/iodine_test.go | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 3742c0790..49451af16 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -20,7 +20,7 @@ }, { "ImportPath": "github.com/minio-io/iodine", - "Rev": "3d54fa6339544392a0eaadcf2692fbc94d4ac21d" + "Rev": "f2dbd51c3b4f8530a9b8e2dbc32788175df2fa5c" }, { "ImportPath": "gopkg.in/check.v1", diff --git a/Godeps/_workspace/src/github.com/minio-io/iodine/iodine.go b/Godeps/_workspace/src/github.com/minio-io/iodine/iodine.go index 0e5004dd9..9cc31cecc 100644 --- a/Godeps/_workspace/src/github.com/minio-io/iodine/iodine.go +++ b/Godeps/_workspace/src/github.com/minio-io/iodine/iodine.go @@ -25,6 +25,8 @@ import ( "strconv" ) +// Error is the iodine error which contains a pointer to the original error +// and stack traces. type Error struct { EmbeddedError error `json:"-"` ErrorMessage string @@ -32,6 +34,7 @@ type Error struct { Stack []StackEntry } +// StackEntry contains the entry in the stack trace type StackEntry struct { Host string File string @@ -39,6 +42,8 @@ type StackEntry struct { 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 { entry := createStackEntry() for k, v := range data { @@ -63,22 +68,23 @@ func createStackEntry() StackEntry { return entry } +// Annotate an error with a stack entry and returns itself func (err *Error) Annotate(info map[string]string) *Error { data := make(map[string]string) - if info != nil { - for k, v := range info { - data[k] = v - } + for k, v := range info { + data[k] = v } entry := createStackEntry() err.Stack = append(err.Stack, entry) 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) } +// EmitHumanReadable returns a human readable error message func (err Error) EmitHumanReadable() string { var errorBuffer bytes.Buffer fmt.Fprintln(&errorBuffer, err.Error()) @@ -88,6 +94,7 @@ func (err Error) EmitHumanReadable() string { return string(errorBuffer.Bytes()) } +// Emits the original error message func (err Error) Error() string { return err.EmbeddedError.Error() } diff --git a/Godeps/_workspace/src/github.com/minio-io/iodine/iodine_test.go b/Godeps/_workspace/src/github.com/minio-io/iodine/iodine_test.go index b8625de36..e14faf59c 100644 --- a/Godeps/_workspace/src/github.com/minio-io/iodine/iodine_test.go +++ b/Godeps/_workspace/src/github.com/minio-io/iodine/iodine_test.go @@ -32,7 +32,7 @@ func TestIodine(t *testing.T) { if len(iodineError.Stack) != 4 { t.Fail() } - jsonResult, err := iodineError.EmitJson() + jsonResult, err := iodineError.EmitJSON() if err != nil { t.Fail() }