{"record":{"id":"745936a75730edf0","repo":"BornToBeRoot/NETworkManager","slug":"wrong-time-unit","errorCode":null,"errorMessage":"Wrong time unit.","messagePattern":"Wrong time unit\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Source/NETworkManager.Utilities/AutoRefreshTime.cs","lineNumber":43,"sourceCode":"    /// </summary>\n    /// <param name=\"info\"><see cref=\"AutoRefreshTimeInfo\" /> to calculate <see cref=\"TimeSpan\" /></param>\n    /// <returns>Returns the calculated <see cref=\"TimeSpan\" />.</returns>\n    public static TimeSpan CalculateTimeSpan(AutoRefreshTimeInfo info)\n    {\n        switch (info.TimeUnit)\n        {\n            // Calculate the seconds\n            case TimeUnit.Second:\n                return new TimeSpan(0, 0, info.Value);\n            // Calculate the minutes\n            case TimeUnit.Minute:\n                return new TimeSpan(0, info.Value * 60, 0);\n            // Calculate the hours\n            case TimeUnit.Hour:\n                return new TimeSpan(info.Value * 60, 0, 0);\n            case TimeUnit.None:\n            default:\n                throw new Exception(\"Wrong time unit.\");\n        }\n    }\n}","sourceCodeStart":25,"sourceCodeEnd":46,"githubUrl":"https://github.com/BornToBeRoot/NETworkManager/blob/2780d65469917a296dbc15f206107d72e2d0115c/Source/NETworkManager.Utilities/AutoRefreshTime.cs#L25-L46","documentation":"AutoRefreshTime.CalculateTimeSpan converts a time unit and value into a TimeSpan. Only Second/Minute/Hour cases are handled; TimeUnit.None or any unhandled unit falls into the default branch which throws Exception('Wrong time unit.'), because no meaningful interval can be computed.","triggerScenarios":"Calling CalculateTimeSpan with info whose TimeUnit is TimeUnit.None (the explicit case) — typically when the auto-refresh feature is disabled (None) but the interval is still calculated.","commonSituations":"Auto-refresh toggle set to 'Off' (None) while a refresh timer tries to compute the next interval; adding a new TimeUnit enum member without extending the switch; deserializing a settings value of 0/None.","solutions":["Check that the TimeUnit is not None before calling CalculateTimeSpan and skip scheduling when auto-refresh is disabled","Handle TimeUnit.None at the call site (disable the timer instead of computing a TimeSpan)","Extend the switch in CalculateTimeSpan if a new TimeUnit member was added","Catch the exception at the caller and fall back to the previous interval"],"exampleFix":"// before\nvar interval = AutoRefreshTime.CalculateTimeSpan(_autoRefreshTime); // throws when None\n// after\nvar interval = _autoRefreshTime.TimeUnit == TimeUnit.None\n    ? Timeout.InfiniteTimeSpan\n    : AutoRefreshTime.CalculateTimeSpan(_autoRefreshTime);","handlingStrategy":"validation","validationCode":"if (info.TimeUnit == TimeUnit.None)\n    return; // auto-refresh disabled; do not compute an interval","typeGuard":"bool HasValidTimeUnit(AutoRefreshTime t) => t.TimeUnit is TimeUnit.Second or TimeUnit.Minute or TimeUnit.Hour;","tryCatchPattern":"try { interval = AutoRefreshTime.CalculateTimeSpan(info); }\ncatch (Exception ex) when (ex.Message == \"Wrong time unit.\") { interval = Timeout.InfiniteTimeSpan; }","preventionTips":["Treat TimeUnit.None as 'feature disabled', not an interval","Check the TimeUnit before computing refresh intervals","Extend CalculateTimeSpan whenever TimeUnit gains new members","Centralize refresh scheduling so None is handled in one place"],"tags":["time","enum","auto-refresh"],"backgroundTag":"unsupported-enum-value","analyzedSha":"2780d65469917a296dbc15f206107d72e2d0115c","analyzedAt":"2026-09-12T17:00:17.986Z","contentChangedAt":"2026-09-12T17:00:17.986Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}