apache/beam · error

unsupported time policy

Error message

unsupported time policy

What it means

The natsio TimestampFn panics when the configured time policy does not match any known policy (processing-time or publishing-time). The library only supports its two enumerated policies and treats any other value as a programming error. This fires at Setup time, i.e. when the DoFn initializes on a worker.

Source

Thrown at sdks/go/pkg/beam/io/natsio/time_policy.go:48

type timestampFn func(time.Time) mtime.Time

func processingTime(_ time.Time) mtime.Time {
	return mtime.Now()
}

func publishingTime(t time.Time) mtime.Time {
	return mtime.FromTime(t)
}

func (p timePolicy) TimestampFn() timestampFn {
	switch p {
	case processingTimePolicy:
		return processingTime
	case publishingTimePolicy:
		return publishingTime
	default:
		panic("unsupported time policy")
	}
}

View on GitHub (pinned to 12126d8942)

Solutions

  1. Set an explicit, supported time policy (processing-time or publishing-time) via the package's option/constructor.
  2. Check that the policy field is not left at its zero value before building the pipeline.
  3. Use the package's exported policy constants/constructors rather than raw values.

Example fix

// before
fn := natsio.NewTimestampFn("eventTime") // unsupported
// after
fn := natsio.NewTimestampFn(natsio.PublishingTimePolicy)
Defensive patterns

Strategy: validation

Validate before calling

if policy != natsio.ProcessingTimePolicy && policy != natsio.PublishingTimePolicy {
    return errors.New("time policy must be processing or publishing time")
}

Try / catch

defer func() {
    if r := recover(); r != nil {
        if s, ok := r.(string); ok && s == "unsupported time policy" {
            // handle
        } else { panic(r) }
    }
}()

Prevention

When it happens

Trigger: Constructing a timestampFn (or configuring the reader) with a policy value that is neither processingTimePolicy nor publishingTimePolicy — e.g. a zero-value struct where the policy field was never set, or a hand-written policy string.

Common situations: Forgetting to apply a WithTimestampPolicy-style option so the field holds its zero value; refactoring policy constants; building a custom DoFn that reuses TimestampFn with an uninitialized policy.

Related errors


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