Skip to content

Commit 14ea604

Browse files
committed
Inline marshalActivityPayloads into its single caller
1 parent 73b6eaa commit 14ea604

2 files changed

Lines changed: 25 additions & 12 deletions

File tree

internal/temporalcli/commands.activity.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,17 @@ func pollActivityOutcome(cctx *CommandContext, cl client.Client, namespace, acti
282282

283283
func printActivityResult(cctx *CommandContext, activityID, runID string, result *common.Payloads) error {
284284
if cctx.JSONOutput {
285-
resultJSON, err := marshalActivityPayloads(cctx, result)
285+
var resultJSON json.RawMessage
286+
var err error
287+
if cctx.JSONShorthandPayloads {
288+
var valuePtr any
289+
if err = converter.GetDefaultDataConverter().FromPayloads(result, &valuePtr); err != nil {
290+
return fmt.Errorf("failed decoding result: %w", err)
291+
}
292+
resultJSON, err = json.Marshal(valuePtr)
293+
} else {
294+
resultJSON, err = cctx.MarshalProtoJSON(result)
295+
}
286296
if err != nil {
287297
return fmt.Errorf("failed marshaling result: %w", err)
288298
}
@@ -317,17 +327,6 @@ func printActivityResult(cctx *CommandContext, activityID, runID string, result
317327
}, printer.StructuredOptions{})
318328
}
319329

320-
func marshalActivityPayloads(cctx *CommandContext, payloads *common.Payloads) (json.RawMessage, error) {
321-
if cctx.JSONShorthandPayloads {
322-
var valuePtr any
323-
if err := converter.GetDefaultDataConverter().FromPayloads(payloads, &valuePtr); err != nil {
324-
return nil, err
325-
}
326-
return json.Marshal(valuePtr)
327-
}
328-
return cctx.MarshalProtoJSON(payloads)
329-
}
330-
331330
func printActivityFailure(cctx *CommandContext, activityID, runID string, f *failure.Failure) error {
332331
if cctx.JSONOutput {
333332
failureJSON, err := cctx.MarshalProtoJSON(f)

internal/temporalcli/commands.activity_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,20 @@ func (s *SharedServerSuite) TestActivity_SearchAttributes_Datetime() {
12151215
}, 5*time.Second, 200*time.Millisecond)
12161216
}
12171217

1218+
func (s *SharedServerSuite) TestActivity_SearchAttributes_InvalidKeywordList() {
1219+
res := s.Execute(
1220+
"activity", "start",
1221+
"--activity-id", "sa-invalid-kwlist",
1222+
"--type", "DevActivity",
1223+
"--task-queue", s.Worker().Options.TaskQueue,
1224+
"--start-to-close-timeout", "30s",
1225+
"--search-attribute", `Foo=[1,"a"]`,
1226+
"--address", s.Address(),
1227+
)
1228+
s.Error(res.Err)
1229+
s.Contains(res.Err.Error(), "array element 0 is float64, not string")
1230+
}
1231+
12181232
func (s *SharedServerSuite) TestActivity_List_Pagination() {
12191233
s.Worker().OnDevActivity(func(ctx context.Context, a any) (any, error) {
12201234
return "paginated", nil

0 commit comments

Comments
 (0)