temporalio / cli

Command-line interface for running Temporal Server and interacting with Workflows, Activities, Namespaces, and other parts of Temporal
https://docs.temporal.io/cli
MIT License
241 stars 32 forks source link

[Bug] Failure to print JSON result #607

Closed dandavison closed 3 days ago

dandavison commented 1 week ago

temporal workflow execute is printing out the following, when it should be printing out the workflow result:

Result          <failed converting to string: json: error calling MarshalJSON for type json.RawMessage: invalid character ':' after object key:value pair>

The real result, copied from the Temporal web UI is

[{"name":"PipelineOmesDev","description":null,"clusterName":"ns-cdcc3be1","Failed":true,"errors":["child workflow execution error (type: DeployApplication, workflowID: PipelineOmesDev/cdcc3be1/DeployApplication, runID: c570a798-cc13-42a4-a5c9-0c0bf8519c1e, initiatedEventID: 5, startedEventID: 6): failed deploying helm chart temporal: activity error (type: DeployHelmChart, scheduledEventID: 23, startedEventID: 24, identity: 74067@dan-2.local@): Get \"https://github.com/temporalio/helm-charts.git/info/refs?service=git-upload-pack\": context deadline exceeded (type: Error, retryable: true): context deadline exceeded (type: deadlineExceededError, retryable: true) (type: wrapError, retryable: true): activity error (type: DeployHelmChart, scheduledEventID: 23, startedEventID: 24, identity: 74067@dan-2.local@): Get \"https://github.com/temporalio/helm-charts.git/info/refs?service=git-upload-pack\": context deadline exceeded (type: Error, retryable: true): context deadline exceeded (type: deadlineExceededError, retryable: true)"],"warnings":null,"workflowID":"","runID":"","startTime":"0001-01-01T00:00:00Z","closeTime":"0001-01-01T00:00:00Z","output":{"testsOutput":null},"canaryErrors":null,"application":{"Releases":null,"KubeObjects":null,"ChartOutputs":null},"cleanupWorkflowID":"PipelineOmesDev/cdcc3be1/CleanupPipeline"}]

That error comes from here in the CLI codebase https://github.com/temporalio/cli/blob/bac68a47856cbe39778e8ba6c3c6e58c09e5aca6/temporalcli/internal/printer/printer.go#L423

If I change that to print out the v input variable, using

diff --git a/temporalcli/internal/printer/printer.go b/temporalcli/internal/printer/printer.go
index 6e84213..424dbd4 100644
--- a/temporalcli/internal/printer/printer.go
+++ b/temporalcli/internal/printer/printer.go
@@ -420,7 +420,7 @@ func (p *Printer) textVal(v any) string {
        } else if (ref.Kind() == reflect.Struct && ref.CanInterface()) || ref.Type().Implements(jsonMarshalerType) {
            b, err := p.jsonVal(v, "", true)
            if err != nil {
-               return fmt.Sprintf("<failed converting to string: %v>", err)
+               return fmt.Sprintf("<failed converting to string: %v\n%s>", err, v)
            }
            return string(b)
        } else if ref.Kind() == reflect.Slice {

we see (notice malformed {"ChartOutputs":"KubeObjects":"Releases":}):

{"Failed":true,"application":{"ChartOutputs":"KubeObjects":"Releases":},"canaryErrors":"cleanupWorkflowID":"PipelineOmesDev/cdcc3be1/CleanupPipeline","closeTime":"0001-01-01T00:00:00Z","clusterName":"ns-cdcc3be1","
description":"errors":["child workflow execution error (type: DeployApplication, workflowID: PipelineOmesDev/cdcc3be1/DeployApplication, runID: c570a798-cc13-42a4-a5c9-0c0bf8519c1e, initiatedEventID: 5, startedEven
tID: 6): failed deploying helm chart temporal: activity error (type: DeployHelmChart, scheduledEventID: 23, startedEventID: 24, identity: 74067@dan-2.local@): Get \"https://github.com/temporalio/helm-charts.git/inf
o/refs?service=git-upload-pack\": context deadline exceeded (type: Error, retryable: true): context deadline exceeded (type: deadlineExceededError, retryable: true) (type: wrapError, retryable: true): activity erro
r (type: DeployHelmChart, scheduledEventID: 23, startedEventID: 24, identity: 74067@dan-2.local@): Get \"https://github.com/temporalio/helm-charts.git/info/refs?service=git-upload-pack\": context deadline exceeded
(type: Error, retryable: true): context deadline exceeded (type: deadlineExceededError, retryable: true)"],"name":"PipelineOmesDev","output":{"testsOutput":},"runID":"","startTime":"0001-01-01T00:00:00Z","warnings"
:"workflowID":""}

(I have not created a reproduction.)

Environment/Versions

CLI built from latest main: bac68a47856cbe39778e8ba6c3c6e58c09e5aca6

cretz commented 6 days ago

Note, this is an issue with shorthand payload work in https://github.com/temporalio/api-go but there is no issues area there to add it

cretz commented 6 days ago

Probably should also solve https://github.com/temporalio/cli/issues/613 at the same time