{"record":{"id":"31f6fec59e6b84b1","repo":"nilaoda/N_m3u8DL-RE","slug":"invalid-speed-limit-input","errorCode":null,"errorMessage":"Invalid Speed Limit: {input}","messagePattern":"Invalid Speed Limit: (.+?)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs","lineNumber":130,"sourceCode":"    private static readonly Option<StreamFilter?> AudioFilter = new(\"-sa\", \"--select-audio\") { HelpName = \"OPTIONS\", Description = ResString.cmd_selectAudio, CustomParser = ParseStreamFilter };\n    private static readonly Option<StreamFilter?> SubtitleFilter = new(\"-ss\", \"--select-subtitle\") { HelpName = \"OPTIONS\", Description = ResString.cmd_selectSubtitle, CustomParser = ParseStreamFilter };\n\n    private static readonly Option<StreamFilter?> DropVideoFilter = new(\"-dv\", \"--drop-video\") { HelpName = \"OPTIONS\", Description = ResString.cmd_dropVideo, CustomParser = ParseStreamFilter };\n    private static readonly Option<StreamFilter?> DropAudioFilter = new(\"-da\", \"--drop-audio\") { HelpName = \"OPTIONS\", Description = ResString.cmd_dropAudio, CustomParser = ParseStreamFilter };\n    private static readonly Option<StreamFilter?> DropSubtitleFilter = new(\"-ds\", \"--drop-subtitle\") { HelpName = \"OPTIONS\", Description = ResString.cmd_dropSubtitle, CustomParser = ParseStreamFilter };\n\n    /// <summary>\n    /// 解析下载速度限制\n    /// </summary>\n    /// <param name=\"result\"></param>\n    /// <returns></returns>\n    private static long? ParseSpeedLimit(ArgumentResult result)\n    {\n        var input = result.Tokens[0].Value.ToUpper();\n        try\n        {\n            var reg = SpeedStrRegex();\n            if (!reg.IsMatch(input)) throw new ArgumentException($\"Invalid Speed Limit: {input}\");\n\n            var number = double.Parse(reg.Match(input).Groups[1].Value);\n            if (reg.Match(input).Groups[2].Value == \"M\")\n                return (long)(number * 1024 * 1024);\n            return (long)(number * 1024);\n        }\n        catch (Exception)\n        {\n            result.AddError(\"error in parse SpeedLimit: \" + input);\n            return null;\n        }\n    }\n\n    /// <summary>\n    /// 解析用户定义的下载范围\n    /// </summary>\n    /// <param name=\"result\"></param>\n    /// <returns></returns>","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/nilaoda/N_m3u8DL-RE/blob/e113dee70c924ee08dae5460624909b04d84cb76/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs#L112-L148","documentation":"CommandInvoker.ParseSpeedLimit validates the --speed-limit (or equivalent) CLI option value against SpeedStrRegex, which expects a number followed by a unit (K or M, e.g. '10M' or '512k'). If the input does not match the expected '<number>[K|M]' format, it throws ArgumentException \"Invalid Speed Limit: {input}\" before the download starts.","triggerScenarios":"The user passes a speed limit value that does not match the number+K/M pattern, e.g. '10Mbps', '10 MB/s', '0.5G', 'abc', or a bare number with an unsupported unit suffix.","commonSituations":"Typos like '10M/s' or '10mbps'; users assuming bits vs bytes or G/T units are accepted; quoting/whitespace issues in shell scripts; localization decimal commas ('1,5M').","solutions":["Use the accepted format: a plain number optionally followed by K or M, e.g. '10M' or '512K' (bytes/s).","Remove unit suffixes like 'bps', '/s', or spaces: '10Mbps' -> '10M'.","Use only K/M units; convert G to M (e.g. '1G' -> '1024M').","Use '.' as the decimal separator, not ','."],"exampleFix":"// before\n--speed-limit \"10Mbps\"\n// after\n--speed-limit \"10M\"","handlingStrategy":"validation","validationCode":"// validate the speed limit against the same pattern the CLI uses\nstatic bool IsValidSpeedLimit(string input) =>\n    System.Text.RegularExpressions.Regex.IsMatch(\n        (input ?? \"\").ToUpperInvariant(), @\"^([0-9]+(?:\\.[0-9]+)?)([KM])$\");\nif (!IsValidSpeedLimit(userInput)) throw new ArgumentException($\"Invalid Speed Limit: {userInput}\");","typeGuard":null,"tryCatchPattern":"try { cli.Parse(args); }\ncatch (ArgumentException ex) when (ex.Message.StartsWith(\"Invalid Speed Limit\")) {\n    Console.Error.WriteLine($\"{ex.Message} -- use format like '10M' or '512K' (bytes/s)\");\n    Environment.Exit(1);\n}","preventionTips":["Document and use the '<number>[K|M]' format (e.g. 10M, 512K).","Strip suffixes like 'bps' or '/s' from user input before passing.","Convert G/T units to M before use.","Use '.' as decimal separator, not ','."],"tags":["cli","argument-validation","speed-limit"],"backgroundTag":"invalid-cli-argument","analyzedSha":"e113dee70c924ee08dae5460624909b04d84cb76","analyzedAt":"2026-09-13T02:43:21.078Z","contentChangedAt":"2026-09-13T02:43:21.078Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}