{"record":{"id":"79d4c130320e6b73","repo":"mgth/LittleBigMouse","slug":"enter-a-test-level-between-0-and-10","errorCode":null,"errorMessage":"Enter a test level between 0 and 10.","messagePattern":"Enter a test level between 0 and 10\\.","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"LittleBigMouse.Plugins/LittleBigMouse.Plugin.Vcp.Avalonia/HisenseVidaa/HisenseVidaaProtocol.cs","lineNumber":214,"sourceCode":"            throw new ArgumentOutOfRangeException(nameof(volume), \"Enter a volume between 0 and 100.\");\n        return volume.ToString(CultureInfo.InvariantCulture);\n    }\n\n    public static string PlatformActionName(string action)\n    {\n        var normalized = action.Trim();\n        if (normalized.Length is 0 or > 64\n            || normalized.Any(c => !char.IsAsciiLetterOrDigit(c) && c is not '_' and not '-'))\n            throw new ArgumentException(\n                \"Enter a platform action name containing only letters, digits, '_' or '-'.\",\n                nameof(action));\n        return normalized;\n    }\n\n    public static string ExperimentalLevelPayload(int value)\n    {\n        if (value is < 0 or > 10)\n            throw new ArgumentOutOfRangeException(nameof(value), \"Enter a test level between 0 and 10.\");\n        return value.ToString(CultureInfo.InvariantCulture);\n    }\n\n    public static bool TryParseVolume(string topic, string payload, out int volume)\n    {\n        volume = 0;\n        if (!topic.EndsWith(\"/platform_service/actions/volumechange\", StringComparison.OrdinalIgnoreCase))\n            return false;\n        try\n        {\n            using var json = JsonDocument.Parse(payload);\n            return json.RootElement.TryGetProperty(\"volume_value\", out var value)\n                   && value.TryGetInt32(out volume)\n                   && volume is >= 0 and <= 100;\n        }\n        catch (JsonException)\n        {\n            return false;","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/mgth/LittleBigMouse/blob/7a42f01d47d99d223b8ee33ba4019af82adf1c48/LittleBigMouse.Plugins/LittleBigMouse.Plugin.Vcp.Avalonia/HisenseVidaa/HisenseVidaaProtocol.cs#L196-L232","documentation":"ExperimentalLevelPayload serializes an integer experimental/test level value into a payload string for the Hisense VIDAA protocol. Only values 0 through 10 are accepted; anything outside that range throws ArgumentOutOfRangeException, since the device firmware only understands test levels in that band.","triggerScenarios":"Calling ExperimentalLevelPayload with an int less than 0 or greater than 10, e.g. ExperimentalLevelPayload(-1) or ExperimentalLevelPayload(11), typically from a slider/numeric input not clamped before submission.","commonSituations":"A UI slider or text box allowing values beyond 0-10; copying a percentage (0-100) instead of a 0-10 level; off-by-one bounds like 10 vs 11; parsing user input without range validation.","solutions":["Clamp the value with Math.Clamp(value, 0, 10) before calling ExperimentalLevelPayload.","Validate the range in the UI layer (slider min=0 max=10) so out-of-range values cannot be produced.","Parse user input as int and check 0 <= value <= 10 before invoking the API.","Catch ArgumentOutOfRangeException to show the 'Enter a test level between 0 and 10' message."],"exampleFix":"// before\nvar payload = ExperimentalLevelPayload(level); // level = 42\n// after\nvar payload = ExperimentalLevelPayload(Math.Clamp(level, 0, 10));","handlingStrategy":"validation","validationCode":"public static bool IsValidExperimentalLevel(int value) => value is >= 0 and <= 10;\n// use: if (!IsValidExperimentalLevel(level)) level = Math.Clamp(level, 0, 10);","typeGuard":null,"tryCatchPattern":"try { var payload = HisenseVidaaProtocol.ExperimentalLevelPayload(level); }\ncatch (ArgumentOutOfRangeException) { level = Math.Clamp(level, 0, 10); }","preventionTips":["Clamp with Math.Clamp(value, 0, 10) at every call site.","Bind the UI control to min=0, max=10.","Convert percentages (0-100) to levels explicitly before sending."],"tags":["argument-validation","range-check","hisense","integer"],"backgroundTag":"value-out-of-range","analyzedSha":"7a42f01d47d99d223b8ee33ba4019af82adf1c48","analyzedAt":"2026-09-16T00:35:00.514Z","contentChangedAt":"2026-09-16T00:35:00.514Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}