fix: JSON output for workflow update execute/result commands#1009
Open
wucm667 wants to merge 1 commit intotemporalio:mainfrom
Open
fix: JSON output for workflow update execute/result commands#1009wucm667 wants to merge 1 commit intotemporalio:mainfrom
wucm667 wants to merge 1 commit intotemporalio:mainfrom
Conversation
- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When using
-o jsonwithtemporal workflow update executeortemporal workflow update result:Update failure returns no JSON — errors are returned as plain
fmt.Errorf, breaking JSON output mode. Users expect structured JSON even on failure.--no-json-shorthand-payloadsflag is silently ignored — update results always decode payloads with the default converter, regardless of the flag. This differs from other commands likeactivity completewhich properly respect this option.Root Cause
Located in
workflowUpdateHelper(internal/temporalcli/commands.workflow.go):fmt.Errorf("unable to update workflow: %w", err), which bypasses the JSON printer entirely.interface{}without checkingcctx.JSONShorthandPayloads, ignoring the--no-json-shorthand-payloadsflag.Fix
JSON error output: When
cctx.JSONOutputis true and the update fails, usecctx.Printer.PrintStructuredto return a structured JSON response withname,updateId, anderrorfields. Falls back to the existingfmt.Errorffor non-JSON mode.Respect
--no-json-shorthand-payloads: Added conditional serialization based oncctx.JSONShorthandPayloads:true(default): decode payloads viaconverter.GetDefaultDataConverter().FromPayloads()for clean JSON outputfalse: usecctx.MarshalProtoJSON()for raw protobuf JSON representationThis matches the pattern used in
printActivityResult(commands.activity.goline 282).Testing
TestWorkflow_Update_ExecuteandTestWorkflow_Update_Resulttests pass.go build ./internal/temporalcli/....Fixes #952