Skip to content

Commit

Permalink
Merge pull request #435 from reubenmiller/fix-add-hint-on-invalid-data
Browse files Browse the repository at this point in the history
fix(data): add user hint to use template flag when unsupported json array is detected
  • Loading branch information
reubenmiller authored Feb 16, 2025
2 parents ed2978f + 4adb152 commit 5a95089
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/flags/getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,12 @@ func WithDataValueAdvanced(stripCumulocityKeys bool, raw bool, opts ...string) G

// Merge multiple data objects together
for _, value := range values {
err = jsonUtilities.ParseJSON(resolveContents(value), data)
v := resolveContents(value)
// data flag does not yet support arrays
if jsonUtilities.IsValidJSON([]byte(v)) && jsonUtilities.IsJSONArray([]byte(v)) {
return dst, "", fmt.Errorf("invalid data type (array) provided on the '%s' flag. Currently only key/value or json objects are supported. Hint: Try using the 'template' flag instead", src)
}
err = jsonUtilities.ParseJSON(v, data)
if err != nil {
return dst, "", fmt.Errorf("json error: %s parameter does not contain valid json or shorthand json. %w", src, err)
}
Expand Down

0 comments on commit 5a95089

Please sign in to comment.