Skip to content

Commit f082bec

Browse files
authored
Merge pull request #2138 from kushal9897/fix/json-array-error-message
Improve error message for top-level arrays
2 parents 649bda9 + 7ec9470 commit f082bec

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

stores/json/store.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,10 @@ func (store Store) treeBranchFromJSON(in []byte) (sops.TreeBranch, error) {
258258
}
259259
if delim, ok := value.(json.Delim); ok {
260260
if delim.String() != "{" {
261-
return nil, fmt.Errorf("Expected JSON object start, got delimiter %s instead", value)
261+
return nil, fmt.Errorf("SOPS only supports JSON files with a top-level object (starting with '{'), not arrays or other types. Got delimiter %s instead. To encrypt this file, wrap it in an object, e.g., {\"data\": [...]}", value)
262262
}
263263
} else {
264-
return nil, fmt.Errorf("Expected JSON object start, got %#v of type %T instead", value, value)
264+
return nil, fmt.Errorf("SOPS only supports JSON files with a top-level object (starting with '{'), not other JSON types. Got %#v of type %T instead", value, value)
265265
}
266266
return store.treeBranchFromJSONDecoder(dec)
267267
}

stores/json/store_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,14 @@ func TestDecodeNumber(t *testing.T) {
132132
in := `42`
133133
_, err := Store{}.treeBranchFromJSON([]byte(in))
134134
assert.NotNil(t, err)
135-
assert.Equal(t, "Expected JSON object start, got 42 of type float64 instead", err.Error())
135+
assert.Equal(t, "SOPS only supports JSON files with a top-level object (starting with '{'), not other JSON types. Got 42 of type float64 instead", err.Error())
136136
}
137137

138138
func TestDecodeArray(t *testing.T) {
139139
in := ` [42] `
140140
_, err := Store{}.treeBranchFromJSON([]byte(in))
141141
assert.NotNil(t, err)
142-
assert.Equal(t, "Expected JSON object start, got delimiter [ instead", err.Error())
142+
assert.Equal(t, "SOPS only supports JSON files with a top-level object (starting with '{'), not arrays or other types. Got delimiter [ instead. To encrypt this file, wrap it in an object, e.g., {\"data\": [...]}", err.Error())
143143
}
144144

145145
func TestDecodeEmpty(t *testing.T) {

0 commit comments

Comments
 (0)