Skip to content

Commit c8780d6

Browse files
committed
Print debugConfig if supplied; fix RawMessage use
Summary: When we use debugConfig, it's nice to say what tweaks happened in the log. To avoid golang/go#6528, needed to switch to using *json.RawMessage. Test Plan: Existing unit doesn't cover it, sadly, but should be quite safe. Reviewers: nate Reviewed By: nate Subscribers: changesbot, anupc Differential Revision: https://tails.corp.dropbox.com/D147620
1 parent 5e85d29 commit c8780d6

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

client/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,17 @@ type Config struct {
6363
// If this build is expected to generate a snapshot, this is the snapshot ID.
6464
ID string
6565
}
66-
DebugConfig map[string]json.RawMessage `json:"debugConfig"`
66+
DebugConfig map[string]*json.RawMessage `json:"debugConfig"`
6767
}
6868

6969
// GetDebugConfig parses the debug config JSON at the given key to dest, returning whether the key
7070
// was present, and if it was, any error that occurred in trying to parse it to dest.
7171
func (c *Config) GetDebugConfig(key string, dest interface{}) (present bool, err error) {
7272
data, ok := c.DebugConfig[key]
73-
if !ok {
73+
if !ok || data == nil {
7474
return false, nil
7575
}
76-
e := json.Unmarshal([]byte(data), dest)
76+
e := json.Unmarshal([]byte(*data), dest)
7777
if e != nil {
7878
e = fmt.Errorf("Malformed JSON in debug config key %q: %s", key, e)
7979
}

engine/engine.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package engine
22

33
import (
4+
"encoding/json"
45
"errors"
56
"flag"
67
"fmt"
@@ -127,6 +128,14 @@ func (e *Engine) Run() (Result, error) {
127128

128129
e.clientLog.Printf("changes-client version: %s", version.GetVersion())
129130
e.clientLog.Printf("Running jobstep %s for %s (%s)", e.config.JobstepID, e.config.Project.Name, e.config.Project.Slug)
131+
if e.config.DebugConfig != nil {
132+
if jsout, err := json.MarshalIndent(e.config.DebugConfig, "", " "); err != nil {
133+
// Should never happen, but no use crashing about it.
134+
sentry.Error(err, map[string]string{})
135+
} else {
136+
e.clientLog.Printf("Debug config: %s", jsout)
137+
}
138+
}
130139

131140
if err := e.checkForSnapshotInconsistency(); err != nil {
132141
sentry.Error(err, map[string]string{})

0 commit comments

Comments
 (0)