Probe error should be marshalled as json.RawMessage to avoid re-encoding of an already marshalled string

This commit is contained in:
Harshavardhana
2015-08-16 11:23:51 -07:00
parent 27016a122e
commit 6313bb2c46
2 changed files with 9 additions and 6 deletions
+5 -2
View File
@@ -17,6 +17,7 @@
package main
import (
"encoding/json"
"os"
"reflect"
@@ -36,7 +37,8 @@ func fatalIf(err *probe.Error) {
EmbeddedError: err.ToError(),
}
if globalDebugFlag {
errorMessage.ProbeError = err.JSON()
rawProbe := json.RawMessage(err.JSON())
errorMessage.ProbeError = &rawProbe
}
console.Println(errorMessage)
os.Exit(1)
@@ -59,7 +61,8 @@ func errorIf(err *probe.Error) {
EmbeddedError: err.ToError(),
}
if globalDebugFlag {
errorMessage.ProbeError = err.JSON()
rawProbe := json.RawMessage(err.JSON())
errorMessage.ProbeError = &rawProbe
}
console.Println(errorMessage)
return
+4 -4
View File
@@ -29,10 +29,10 @@ import (
// ErrorMessage json container for error messages
type ErrorMessage struct {
Type string `json:"type"`
TypedError string `json:"typed-error"`
EmbeddedError error `json:"embedded-error"`
ProbeError string `json:"probe-error"`
Type string `json:"type"`
TypedError string `json:"typed-error"`
EmbeddedError error `json:"embedded-error"`
ProbeError *json.RawMessage `json:"probe-error,omitempty"`
}
func (e ErrorMessage) String() string {