From 6313bb2c46d6a2d65ddc18da506062ed8427e63d Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sun, 16 Aug 2015 11:23:51 -0700 Subject: [PATCH] Probe error should be marshalled as json.RawMessage to avoid re-encoding of an already marshalled string --- error.go | 7 +++++-- print-structs.go | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/error.go b/error.go index 702182e0..97a6dfe1 100644 --- a/error.go +++ b/error.go @@ -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 diff --git a/print-structs.go b/print-structs.go index cc39d957..b46f96b1 100644 --- a/print-structs.go +++ b/print-structs.go @@ -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 {