Skip to content

fix(cli): warn when --data fields cannot be sent - #225

Merged
ysyneu merged 1 commit into
mainfrom
fix/warn-dropped-data-fields
Oct 12, 2026
Merged

ysyneu merged 1 commit into
mainfrom
fix/warn-dropped-data-fields

Conversation

@ysyneu

@ysyneu ysyneu commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Problem

--data bodies are bound into the SDK request struct with json.Unmarshal, which silently discards fields the struct does not declare. When the server accepts a field that the bundled SDK does not know yet (or the caller mistypes a key), the field disappears before the request is sent and the command still exits 0.

Change

  • genBindBody takes an io.Writer and, after binding, walks the body against the request type (unboundFields / wireField, following encoding/json name matching: exact then case-insensitive, untagged embedded structs, url-tagged GET structs, stopping at types with their own UnmarshalJSON).
  • Every dropped path is named on stderr, e.g.
    warning: --data fields not sent, unknown to this CLI version: investigation_targets[].bogus
  • The request is unchanged, so read-modify-write flows that pass extra read-only fields keep working.
  • cligen template and hand-written callers pass ctx.Cmd.ErrOrStderr(); the insight export's second bind of the same body (incident total) passes io.Discard.
  • Generated files regenerated with go run ./internal/cmd/cligen (only the call line changes).

Verification

  • go test ./... passes; make check-cards OK; new unit test covers nested objects, arrays, maps, embedded structs, url tags, case folding and json.RawMessage.
  • Built binary against a local HTTP stub with monit rule-v2-create --data carrying investigation_targets[].purpose plus an unknown key: purpose is in the outgoing body; the unknown key is reported on stderr.

Also supersedes #223: main already carries go-flashduty v0.15.15 (which includes the purpose field) via #224.

genBindBody binds the --data body into the SDK request struct with
json.Unmarshal, which silently discards any field the struct lacks. A field
newer than the bundled SDK (or a mistyped one) therefore vanished before the
request left the client while the call still succeeded.

genBindBody now walks the body against the request type and names every
dropped path on stderr (nested fields as a.b, array elements as a[].b). The
request itself is unchanged, so read-modify-write flows that pass extra
read-only fields keep working. The insight export's second bind of the same
body (incident total) discards the warning to avoid a duplicate.
@ysyneu
ysyneu merged commit 84e7bb5 into main Oct 12, 2026
12 checks passed
@ysyneu
ysyneu deleted the fix/warn-dropped-data-fields branch October 12, 2026 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant