{"record":{"id":"063db8e584ea551b","repo":"Cysharp/UniTask","slug":"delay-does-not-allow-minus-intervalframecount-int","errorCode":null,"errorMessage":"Delay does not allow minus intervalFrameCount. intervalFrameCount:","messagePattern":"Delay does not allow minus intervalFrameCount\\. intervalFrameCount:","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/UniTask/Assets/Plugins/UniTask/Runtime/Linq/UnityExtensions/Timer.cs","lineNumber":52,"sourceCode":"        public static IUniTaskAsyncEnumerable<AsyncUnit> TimerFrame(int dueTimeFrameCount, int periodFrameCount, PlayerLoopTiming updateTiming = PlayerLoopTiming.Update, bool cancelImmediately = false)\n        {\n            if (dueTimeFrameCount < 0)\n            {\n                throw new ArgumentOutOfRangeException(\"Delay does not allow minus delayFrameCount. dueTimeFrameCount:\" + dueTimeFrameCount);\n            }\n            if (periodFrameCount < 0)\n            {\n                throw new ArgumentOutOfRangeException(\"Delay does not allow minus periodFrameCount. periodFrameCount:\" + dueTimeFrameCount);\n            }\n\n            return new TimerFrame(dueTimeFrameCount, periodFrameCount, updateTiming, cancelImmediately);\n        }\n\n        public static IUniTaskAsyncEnumerable<AsyncUnit> IntervalFrame(int intervalFrameCount, PlayerLoopTiming updateTiming = PlayerLoopTiming.Update, bool cancelImmediately = false)\n        {\n            if (intervalFrameCount < 0)\n            {\n                throw new ArgumentOutOfRangeException(\"Delay does not allow minus intervalFrameCount. intervalFrameCount:\" + intervalFrameCount);\n            }\n            return new TimerFrame(intervalFrameCount, intervalFrameCount, updateTiming, cancelImmediately);\n        }\n    }\n\n    internal class Timer : IUniTaskAsyncEnumerable<AsyncUnit>\n    {\n        readonly PlayerLoopTiming updateTiming;\n        readonly TimeSpan dueTime;\n        readonly TimeSpan? period;\n        readonly bool ignoreTimeScale;\n        readonly bool cancelImmediately;\n\n        public Timer(TimeSpan dueTime, TimeSpan? period, PlayerLoopTiming updateTiming, bool ignoreTimeScale, bool cancelImmediately)\n        {\n            this.updateTiming = updateTiming;\n            this.dueTime = dueTime;\n            this.period = period;","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/Cysharp/UniTask/blob/ceac8d6946b1125fe782cd171fbcb245b567dbf9/src/UniTask/Assets/Plugins/UniTask/Runtime/Linq/UnityExtensions/Timer.cs#L34-L70","documentation":"Thrown by IntervalFrame(intervalFrameCount) when intervalFrameCount is negative. IntervalFrame creates a repeating frame timer where the interval equals both the due time and period. A negative interval is meaningless.","triggerScenarios":"Passing a negative integer to UniTaskAsyncEnumerable.IntervalFrame(intervalFrameCount). E.g., a computed interval from a configuration that allows negative values.","commonSituations":"Dynamic interval calculation that underflows. Config-driven scheduling with unvalidated input. Using IntervalFrame with a frame budget that went negative.","solutions":["Clamp the value: var interval = Math.Max(0, intervalFrameCount); before calling IntervalFrame.","Fix the upstream calculation or configuration that produced the negative value."],"exampleFix":"// before\nawait UniTaskAsyncEnumerable.IntervalFrame(configuredInterval).ForEachAwaitAsync(_ => { });\n// throws if configuredInterval < 0\n\n// after\nvar interval = Math.Max(1, configuredInterval);\nawait UniTaskAsyncEnumerable.IntervalFrame(interval).ForEachAwaitAsync(_ => { });","handlingStrategy":"validation","validationCode":"var safeInterval = Math.Max(0, intervalFrameCount);\nawait UniTaskAsyncEnumerable.IntervalFrame(safeInterval).ForEachAwaitAsync(_ => { });","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp intervalFrameCount with Math.Max(0, value) before calling IntervalFrame.","Validate config-driven interval values against negative inputs at the parsing boundary."],"tags":["timer","frame-based","argument-validation","interval"],"backgroundTag":null,"analyzedSha":"ceac8d6946b1125fe782cd171fbcb245b567dbf9","analyzedAt":"2026-08-13T19:16:39.025Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}