{"record":{"id":"47ed2e91ebbb9160","repo":"apache/beam","slug":"marshalling-time-v","errorCode":null,"errorMessage":"marshalling time: %v","messagePattern":"marshalling time: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/encoding.go","lineNumber":276,"sourceCode":"\t\t\t\treturn EncodedCoder{}, err\n\t\t\t}\n\t\t\treturn EncodedCoder{Coder: Coder{coder: c}}, nil\n\t\t},\n\t\tnil\n}\n\nfunc timeEnc(reflect.Type) (func(any, io.Writer) error, error) {\n\treturn func(iface any, w io.Writer) error {\n\t\tif err := coder.WriteSimpleRowHeader(1, w); err != nil {\n\t\t\treturn errors.Wrap(err, \"encoding time.Time schema override\")\n\t\t}\n\t\tt := iface.(time.Time)\n\t\t// We use the text marshalling rather than the binary marshalling\n\t\t// since it has more precision. Apparently some info isn't included\n\t\t// in the binary marshal.\n\t\tdata, err := t.MarshalText()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"marshalling time: %v\", err)\n\t\t}\n\t\tif err := coder.EncodeBytes(data, w); err != nil {\n\t\t\treturn err\n\t\t}\n\t\treturn nil\n\t}, nil\n}\n\nfunc timeDec(reflect.Type) (func(io.Reader) (any, error), error) {\n\treturn func(r io.Reader) (any, error) {\n\t\tif err := coder.ReadSimpleRowHeader(1, r); err != nil {\n\t\t\treturn nil, errors.Wrap(err, \"decoding time.Time schema override\")\n\t\t}\n\t\tdata, err := coder.DecodeBytes(r)\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrap(err, \"retrieving time data: %v\")\n\t\t}\n\t\tt := time.Time{}","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/encoding.go#L258-L294","documentation":"Beam's default coder for time.Time serializes values using MarshalText for higher precision. If MarshalText fails during encoding of a pipeline element, the error is wrapped as \"marshalling time\". This is rare since time.Time.MarshalText almost never fails.","triggerScenarios":"Encoding a time.Time element in a Beam pipeline when t.MarshalText() returns an error (e.g. a time value with an unrepresentable state, generally from unsafe construction of a Time struct).","commonSituations":"Pipelines transmitting time.Time elements across worker boundaries; corrupt or zero-valued times created via unsafe.Inspect/time.Time{} manipulation rather than time.Now/time.Parse.","solutions":["Inspect the wrapped error to find the offending element and how the time.Time was constructed.","Construct time.Time values only via time.Now(), time.Parse, etc.; avoid unsafe zero-value or reflection-built times.","If serialization is not needed, convert times to strings/ints before inserting into PCollections."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if _, err := t.MarshalText(); err != nil {\n    return fmt.Errorf(\"element time is unencodable: %w\", err)\n}","typeGuard":"func isEncodableTime(t time.Time) bool { _, err := t.MarshalText(); return err == nil }","tryCatchPattern":"if err := beamRun(ctx, p); err != nil {\n    if strings.Contains(err.Error(), \"marshalling time\") {\n        // inspect elements for badly constructed time.Time values\n    }\n}","preventionTips":["Only construct time.Time via time.Now/time.Parse/time.Unix.","Avoid zero-value or reflection-built time.Time in pipeline elements."],"tags":["go","time","serialization","beam"],"backgroundTag":"json-marshal-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}