Skip to content

fix: improve error messages for invalid payloads in Zeebe command binding#4412

Open
nelson-parente wants to merge 5 commits into
dapr:mainfrom
nelson-parente:fix/zeebe-command-binding-error-messages
Open

fix: improve error messages for invalid payloads in Zeebe command binding#4412
nelson-parente wants to merge 5 commits into
dapr:mainfrom
nelson-parente:fix/zeebe-command-binding-error-messages

Conversation

@nelson-parente

@nelson-parente nelson-parente commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Problem

When a duration field in a Zeebe command binding payload contains an invalid value, the error returned is unhelpful. For example, sending "timeToLive": "PT1M" (ISO-8601 — the format Zeebe itself uses) or "timeToLive": "1minute" produced:

Zeebee binding error: Invalid duration

or

time: invalid duration "PT1M"

Neither message tells the user which field failed, what value was rejected, or what format is expected.

Root cause

metadata.Duration.UnmarshalJSON (in dapr/kit) returns a bare error from time.ParseDuration or errors.New("invalid duration") for invalid inputs. The Go JSON decoder propagates this error through json.Unmarshal with no field-level context, so callers only see the raw parse error.

Affected operations and fields:

Operation Field
publish-message timeToLive
activate-jobs timeout, requestTimeout
fail-job retryBackOff
create-instance requestTimeout

Fix

Implemented UnmarshalJSON on each affected payload struct. Duration fields are decoded individually via a shadow struct using json.RawMessage, allowing parse errors to be wrapped with the field name and a format hint.

Before:

time: invalid duration "PT1M"

After:

invalid value for field 'timeToLive': time: invalid duration "PT1M"; expected a Go duration string (e.g. "30s", "5m", "1h30m")

Note: The accepted format is a Go time.Duration string — e.g. "30s", "5m", "1h30m". ISO-8601 duration strings (like PT1M) are not supported.

Tests

Added 14 unit tests (no live broker required) asserting that:

  • Each duration field name appears in the error message
  • The offending value appears in the error message
  • Format guidance ("duration string") is present
  • Valid Go duration strings continue to parse without error

All 80 tests pass (go test ./bindings/zeebe/...).

Fixes #4093


📖 Documentation: dapr/docs#5220

…ding

When a duration field (timeToLive, timeout, requestTimeout, retryBackOff)
received an invalid value, the binding returned a bare "invalid duration"
or "time: invalid duration ..." error with no indication of which field
failed or what format is expected.

Implement UnmarshalJSON on publishMessagePayload, activateJobsPayload,
failJobPayload, and createInstancePayload to unmarshal duration fields
individually and wrap parse errors with the field name and a format hint
(e.g. "invalid value for field 'timeToLive': ...; expected a Go duration
string (e.g. \"30s\", \"5m\", \"1h30m\")").

Adds 14 unit tests asserting that error messages include the field name,
the offending value, and duration format guidance. All 80 tests pass.

Fixes dapr#4093

Signed-off-by: Nelson Parente <nelson@diagrid.io>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the Zeebe command binding’s user-facing error messages when JSON payload duration fields contain invalid values by adding per-payload UnmarshalJSON implementations that wrap duration parsing errors with field context, and it adds unit tests to validate the new messages.

Changes:

  • Added custom UnmarshalJSON methods to Zeebe command payload structs to wrap duration parsing errors with field names and format hints.
  • Added unit tests covering invalid/valid/null/numeric duration inputs for each affected payload/field.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
bindings/zeebe/command/publish_message.go Adds custom unmarshal for timeToLive to wrap duration parsing errors with field context.
bindings/zeebe/command/publish_message_test.go Adds tests asserting field-scoped duration error messages and regression coverage for numeric/null inputs.
bindings/zeebe/command/fail_job.go Adds custom unmarshal for retryBackOff to wrap duration parsing errors with field context.
bindings/zeebe/command/fail_job_test.go Adds tests asserting field-scoped duration error messages and regression coverage for numeric/null inputs.
bindings/zeebe/command/create_instance.go Adds custom unmarshal for requestTimeout to wrap duration parsing errors with field context.
bindings/zeebe/command/create_instance_test.go Adds tests asserting field-scoped duration error messages and regression coverage for numeric/null inputs.
bindings/zeebe/command/activate_jobs.go Adds custom unmarshal for timeout and requestTimeout to wrap duration parsing errors with field context.
bindings/zeebe/command/activate_jobs_test.go Adds tests asserting field-scoped duration error messages and regression coverage for numeric/null inputs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread bindings/zeebe/command/publish_message.go
Comment thread bindings/zeebe/command/fail_job.go
Comment thread bindings/zeebe/command/create_instance.go
Comment thread bindings/zeebe/command/activate_jobs.go
Comment thread bindings/zeebe/command/activate_jobs.go
…tion errors (Copilot review)

Signed-off-by: Nelson Parente <nelson_parente@live.com.pt>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Comment thread bindings/zeebe/command/publish_message.go
Comment thread bindings/zeebe/command/fail_job.go
Comment thread bindings/zeebe/command/create_instance.go
Comment thread bindings/zeebe/command/activate_jobs.go
Comment thread bindings/zeebe/command/activate_jobs.go
@nelson-parente nelson-parente marked this pull request as ready for review June 19, 2026 09:36
@nelson-parente nelson-parente requested review from a team as code owners June 19, 2026 09:36
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.

Zeebe command binding: Error handling improvement

3 participants