{"record":{"id":"01cd822f8cb13de9","repo":"temporalio/temporal","slug":"unable-to-encode-payloads-v","errorCode":null,"errorMessage":"unable to encode payloads: %v","messagePattern":"unable to encode payloads: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/payloads/payloads.go","lineNumber":59,"sourceCode":"\t}\n\tif len(ps.GetPayloads()) < 1 {\n\t\treturn nil, nil\n\t}\n\treturn ps.GetPayloads()[0], nil\n}\n\nfunc MustEncodeSingle(value any) *commonpb.Payload {\n\tp, err := EncodeSingle(value)\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"unable to encode single payload: %v\", err)) //nolint:forbidigo // Must-helper: callers opt into panic on encode failure\n\t}\n\treturn p\n}\n\nfunc MustEncode(value ...any) *commonpb.Payloads {\n\tp, err := defaultDataConverter.ToPayloads(value...)\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"unable to encode payloads: %v\", err)) //nolint:forbidigo // Must-helper: callers opt into panic on encode failure\n\t}\n\treturn p\n}\n\nfunc Decode(ps *commonpb.Payloads, valuePtr ...any) error {\n\treturn defaultDataConverter.FromPayloads(ps, valuePtr...)\n}\n\nfunc ToString(ps *commonpb.Payloads) string {\n\treturn fmt.Sprintf(\"[%s]\", strings.Join(defaultDataConverter.ToStrings(ps), \", \"))\n}\n","sourceCodeStart":41,"sourceCodeEnd":71,"githubUrl":"https://github.com/temporalio/temporal/blob/bde624efd13fbd3843654058db6d9c716166318b/common/payloads/payloads.go#L41-L71","documentation":"MustEncode encodes multiple values into Payloads via the default data converter and panics on error, matching Go's Must* convention where the caller explicitly opts into panic-on-failure. Failures stem from values the converter cannot serialize.","triggerScenarios":"Calling MustEncode with at least one unencodable value (unsupported type, nil, function/channel/map key the JSON/proto converter rejects).","commonSituations":"Passing structs lacking JSON tags when the JSON converter is active; encoding arguments with unexported-only fields that fail round-trip expectations; tests with malformed fixtures.","solutions":["Inspect the panic message to identify which value failed and why","Switch to the error-returning payloads.Encode for fallible inputs","Ensure all encoded types are supported by the configured data converter (add struct tags or a custom converter)","Validate test fixtures for nil/unsupported values"],"exampleFix":"// before\npl := payloads.MustEncode(arg) // panics on unsupported type\n// after\npl, err := payloads.Encode(arg)\nif err != nil {\n\treturn fmt.Errorf(\"encode payloads: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"func canEncodeAll(vs ...any) bool { _, err := payloads.Encode(vs...); return err == nil }","typeGuard":null,"tryCatchPattern":"defer func() {\n\tif r := recover(); r != nil {\n\t\tlogger.Error(\"MustEncode panicked\", r)\n\t\terr = fmt.Errorf(\"payloads encode failed: %v\", r)\n\t}\n}() // around the MustEncode call","preventionTips":["Use the error-returning payloads.Encode for runtime paths; reserve MustEncode for tests","Ensure all argument types are serializable by the default data converter","Check for nil values in variadic inputs before encoding"],"tags":["go","payloads","encoding","panic"],"backgroundTag":"payload-encoding-failed","analyzedSha":"bde624efd13fbd3843654058db6d9c716166318b","analyzedAt":"2026-09-01T07:18:39.080Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}