Skip to content

fix: JSON output for workflow update execute/result commands#1009

Open
wucm667 wants to merge 1 commit intotemporalio:mainfrom
wucm667:fix/workflow-update-json-output
Open

fix: JSON output for workflow update execute/result commands#1009
wucm667 wants to merge 1 commit intotemporalio:mainfrom
wucm667:fix/workflow-update-json-output

Conversation

@wucm667
Copy link
Copy Markdown

@wucm667 wucm667 commented Apr 29, 2026

Problem

When using -o json with temporal workflow update execute or temporal workflow update result:

  1. Update failure returns no JSON — errors are returned as plain fmt.Errorf, breaking JSON output mode. Users expect structured JSON even on failure.

  2. --no-json-shorthand-payloads flag is silently ignored — update results always decode payloads with the default converter, regardless of the flag. This differs from other commands like activity complete which properly respect this option.

Root Cause

Located in workflowUpdateHelper (internal/temporalcli/commands.workflow.go):

  • Line ~488: Update failure returns fmt.Errorf("unable to update workflow: %w", err), which bypasses the JSON printer entirely.
  • Lines ~491-497: Result is printed as interface{} without checking cctx.JSONShorthandPayloads, ignoring the --no-json-shorthand-payloads flag.

Fix

  1. JSON error output: When cctx.JSONOutput is true and the update fails, use cctx.Printer.PrintStructured to return a structured JSON response with name, updateId, and error fields. Falls back to the existing fmt.Errorf for non-JSON mode.

  2. Respect --no-json-shorthand-payloads: Added conditional serialization based on cctx.JSONShorthandPayloads:

    • true (default): decode payloads via converter.GetDefaultDataConverter().FromPayloads() for clean JSON output
    • false: use cctx.MarshalProtoJSON() for raw protobuf JSON representation

This matches the pattern used in printActivityResult (commands.activity.go line 282).

Testing

  • Existing TestWorkflow_Update_Execute and TestWorkflow_Update_Result tests pass.
  • Build compiles cleanly with go build ./internal/temporalcli/....

Fixes #952

- Return structured JSON error output when update fails in JSON mode
  instead of returning a plain error that breaks -o json output
- Respect --no-json-shorthand-payloads flag when printing update results:
  decode payloads with DefaultDataConverter when shorthand is enabled,
  use MarshalProtoJSON for raw payloads when disabled

Fixes temporalio#952

Signed-off-by: wucm667 <stevenwucongmin@gmail.com>
@wucm667 wucm667 requested a review from a team as a code owner April 29, 2026 03:45
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 29, 2026

CLA assistant check
All committers have signed the CLA.

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.

[Bug] Fetching workflow update outcome yields incorrect JSON output in result and error cases

2 participants