{"record":{"id":"1ce71b1fbe795c70","repo":"babalae/better-genshin-impact","slug":"retryinterval-0","errorCode":null,"errorMessage":"retryInterval 必须大于 0","messagePattern":"retryInterval 必须大于 0","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Core/BgiVision/BvLocator.cs","lineNumber":292,"sourceCode":"    {\n        if (timeout <= 0)\n        {\n            throw new ArgumentOutOfRangeException(nameof(timeout), \"timeout 必须大于 0\");\n        }\n        _timeout = timeout;\n        return this;\n    }\n\n    /// <summary>\n    /// 设置重试间隔（毫秒）\n    /// </summary>\n    /// <param name=\"retryInterval\">重试间隔（毫秒）</param>\n    /// <returns></returns>\n    public BvLocator WithRetryInterval(int retryInterval)\n    {\n        if (retryInterval <= 0)\n        {\n            throw new ArgumentOutOfRangeException(nameof(retryInterval), \"retryInterval 必须大于 0\");\n        }\n        _retryInterval = retryInterval;\n        return this;\n    }\n\n    /// <summary>\n    /// 为 JavaScript 提供的动态参数重载\n    /// 解决 ClearScript 无法将 JS 函数隐式转换为 Action 委托的问题\n    /// 支持同步和异步 JS 函数\n    /// </summary>\n    /// <param name=\"action\">JS 回调函数</param>\n    /// <returns></returns>\n    public BvLocator WithRetryAction(dynamic action)\n    {\n        if (action == null)\n        {\n            RetryAction = null;\n        }","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/BgiVision/BvLocator.cs#L274-L310","documentation":"BvLocator.WithRetryInterval rejects any retryInterval value <= 0 with an ArgumentOutOfRangeException. BvLocator is the fluent locator builder in the BgiVision (BetterGI Vision) DSL; _retryInterval drives the wait between recognition retries when a locator is polled until success or timeout. A non-positive interval would produce a busy-loop or a negative delay, so the guard rejects it eagerly at build time.","triggerScenarios":"Calling GetByText/GetByImage(...).WithRetryInterval(0) or WithRetryInterval(-1); passing a computed/int-parsed interval whose source value is 0; a JS script invoking WithRetryInterval with a zero literal.","commonSituations":"Config-driven scripts that read retryInterval from a settings file and default to 0; copy-paste from WithTimeout where a 0 sentinel means 'use default' (here 0 is invalid); unit tests passing 0 expecting default behavior.","solutions":["Pass a positive millisecond value, e.g. WithRetryInterval(200) for a 200 ms gap.","If the interval comes from config, clamp it: WithRetryInterval(Math.Max(1, config.RetryInterval)).","Omit the call entirely if the BvLocator default retry interval is acceptable."],"exampleFix":"// before\nvar loc = page.GetByText(\"确认\").WithRetryInterval(0);\n\n// after\nvar loc = page.GetByText(\"确认\").WithRetryInterval(200);\n// or guard config-derived values\nvar loc = page.GetByText(\"确认\")\n    .WithRetryInterval(Math.Max(1, cfg.RetryIntervalMs));","handlingStrategy":"validation","validationCode":"// before building the locator\nint interval = sourceInterval; // from config/js\nif (interval <= 0) interval = 200; // sensible default\nvar loc = page.GetByText(\"确认\").WithRetryInterval(interval);","typeGuard":"static bool IsValidRetryInterval(int ms) => ms > 0;","tryCatchPattern":null,"preventionTips":["Always clamp config-derived intervals to >= 1 before passing them to WithRetryInterval.","Document that 0/negative are invalid (unlike WithTimeout-like APIs that may treat 0 as 'default').","Add a unit test asserting WithRetryInterval(0) throws."],"tags":["bgivision","locator","argument-validation","fluent-builder"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}