apache/beam · error

decoding time: %v

Error message

decoding time: %v

What it means

After successfully extracting the raw bytes in the time.Time schema override decoder, the bytes are parsed with time.Time.UnmarshalText (RFC3339 text format). If parsing fails, the error is wrapped as "decoding time". The stored bytes are not a valid textual timestamp.

Source

Thrown at sdks/go/pkg/beam/encoding.go:296

		if err := coder.EncodeBytes(data, w); err != nil {
			return err
		}
		return nil
	}, nil
}

func timeDec(reflect.Type) (func(io.Reader) (any, error), error) {
	return func(r io.Reader) (any, error) {
		if err := coder.ReadSimpleRowHeader(1, r); err != nil {
			return nil, errors.Wrap(err, "decoding time.Time schema override")
		}
		data, err := coder.DecodeBytes(r)
		if err != nil {
			return nil, errors.Wrap(err, "retrieving time data: %v")
		}
		t := time.Time{}
		if err := t.UnmarshalText(data); err != nil {
			return nil, errors.Wrap(err, "decoding time: %v")
		}
		return t, nil
	}, nil
}

View on GitHub (pinned to 12126d8942)

Solutions

  1. Ensure the encoding side uses the same timeEnc override (text-based) that produced these bytes.
  2. Inspect the actual bytes; if they are binary, re-write the data using the matching encoder.
  3. Check the wrapped UnmarshalText error to see the offending value and fix the producer.
  4. If data is legacy binary, migrate it with a one-time conversion job before decoding with this override.

Example fix

// before: binary time written, text expected
buf.Write(t.MarshalBinary())
// after: match the decoder's expectation
text, _ := t.MarshalText()
coder.EncodeBytes(text, buf)
Defensive patterns

Strategy: validation

Validate before calling

var probe time.Time
if err := probe.UnmarshalText(data); err != nil {
    return fmt.Errorf("data is not RFC3339 text: %w", err)
}

Type guard

func isRFC3339(b []byte) bool {
    _, err := time.Parse(time.RFC3339, string(b))
    return err == nil
}

Try / catch

if _, err := time.Parse(time.RFC3339, string(data)); err != nil {
    return fmt.Errorf("invalid stored timestamp %q: %w", data, err)
}

Prevention

When it happens

Trigger: The time bytes retrieved via coder.DecodeBytes do not parse as RFC3339 text — e.g. data written by a non-text encoder (binary time.Time marshal) or garbage/corrupt bytes.

Common situations: Mixing encoders (writing with t.MarshalBinary, reading with the text-based override), hand-edited data, or upgrading Beam while data on disk was written with an older incompatible override.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/49c3cdb5d5cb9b53. Report an issue: GitHub.