{"record":{"id":"64d7f0b95e9ed634","repo":"apache/beam","slug":"can-t-apply-an-alignment-period-of-less-than-a-millisecond","errorCode":null,"errorMessage":"can't apply an alignment period of less than a millisecond. Got: %v","messagePattern":"can't apply an alignment period of less than a millisecond\\. Got: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/graph/window/trigger/trigger.go","lineNumber":171,"sourceCode":"\n// PlusDelay configures an AfterProcessingTime trigger to fire after a specified delay,\n// no smaller than a millisecond.\nfunc (t *AfterProcessingTimeTrigger) PlusDelay(delay time.Duration) *AfterProcessingTimeTrigger {\n\tif delay < time.Millisecond {\n\t\tpanic(fmt.Errorf(\"can't apply processing delay of less than a millisecond. Got: %v\", delay))\n\t}\n\tt.timestampTransforms = append(t.timestampTransforms, DelayTransform{Delay: int64(delay / time.Millisecond)})\n\treturn t\n}\n\n// AlignedTo configures an AfterProcessingTime trigger to fire\n// at the smallest multiple of period since the offset greater than the first element timestamp.\n//\n// * Period may not be smaller than a millisecond.\n// * Offset may be a zero time (time.Time{}).\nfunc (t *AfterProcessingTimeTrigger) AlignedTo(period time.Duration, offset time.Time) *AfterProcessingTimeTrigger {\n\tif period < time.Millisecond {\n\t\tpanic(fmt.Errorf(\"can't apply an alignment period of less than a millisecond. Got: %v\", period))\n\t}\n\toffsetMillis := int64(0)\n\tif !offset.IsZero() {\n\t\t// TODO: Change to call UnixMilli() once we move to only supporting a go version > 1.17.\n\t\toffsetMillis = offset.Unix()*1e3 + int64(offset.Nanosecond())/1e6\n\t}\n\tt.timestampTransforms = append(t.timestampTransforms, AlignToTransform{\n\t\tPeriod: int64(period / time.Millisecond),\n\t\tOffset: offsetMillis,\n\t})\n\treturn t\n}\n\n// RepeatTrigger fires a sub-trigger repeatedly.\ntype RepeatTrigger struct {\n\tsubtrigger Trigger\n}\n","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/graph/window/trigger/trigger.go#L153-L189","documentation":"AlignedTo aligns an AfterProcessingTime trigger to multiples of a period; periods below one millisecond cannot be represented in the millisecond-quantized transform, so the method panics. The offset may be a zero time.Time{} and is optional.","triggerScenarios":"Calling AlignedTo with period < time.Millisecond, e.g. AlignedTo(100 * time.Microsecond, time.Time{}), or a period computed from config as 0.","commonSituations":"Unset config value for the alignment period (0 duration); microsecond-level alignment copied from another framework; unit mistakes in duration arithmetic.","solutions":["Pass an alignment period of at least time.Millisecond.","Clamp the period to time.Millisecond before calling AlignedTo.","Validate the config value supplying the period (guard against 0).","For finer alignment granularity, implement a custom trigger rather than using AlignedTo."],"exampleFix":"// before\nt := trigger.AfterProcessingTime().AlignedTo(cfg.Period, time.Time{}) // cfg.Period may be 0\n// after\np := cfg.Period\nif p < time.Millisecond { p = time.Millisecond }\nt := trigger.AfterProcessingTime().AlignedTo(p, time.Time{})","handlingStrategy":"validation","validationCode":"if period < time.Millisecond { return fmt.Errorf(\"alignment period must be >= 1ms, got %v\", period) }","typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        if strings.Contains(fmt.Sprint(r), \"alignment period\") { return ErrPeriodTooSmall }\n        panic(r)\n    }\n}()","preventionTips":["Validate config values feeding the period (guard against 0)","Floor the period at time.Millisecond","Prefer a custom trigger if sub-ms alignment is required"],"tags":["go","apache-beam","trigger","panic","duration"],"backgroundTag":"invalid-duration-format","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}