{"record":{"id":"e3953dd6774390a3","repo":"nilaoda/N_m3u8DL-RE","slug":"bad-format","errorCode":null,"errorMessage":"Bad format!","messagePattern":"Bad format!","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs","lineNumber":161,"sourceCode":"\n    /// <summary>\n    /// 解析用户定义的下载范围\n    /// </summary>\n    /// <param name=\"result\"></param>\n    /// <returns></returns>\n    /// <exception cref=\"ArgumentException\"></exception>\n    private static CustomRange? ParseCustomRange(ArgumentResult result)\n    {\n        var input = result.Tokens[0].Value;\n        // 支持的种类 0-100; 01:00:00-02:30:00; -300; 300-; 05:00-; -03:00;\n        try\n        {\n            if (string.IsNullOrEmpty(input))\n                return null;\n\n            var arr = input.Split('-');\n            if (arr.Length != 2)\n                throw new ArgumentException(\"Bad format!\");\n\n            if (input.Contains(':'))\n            {\n                return new CustomRange()\n                {\n                    InputStr = input,\n                    StartSec = arr[0] == \"\" ? 0 : OtherUtil.ParseDur(arr[0]).TotalSeconds,\n                    EndSec = arr[1] == \"\" ? double.MaxValue : OtherUtil.ParseDur(arr[1]).TotalSeconds,\n                };\n            }\n\n            if (RangeRegex().IsMatch(input))\n            {\n                var left = RangeRegex().Match(input).Groups[1].Value;\n                var right = RangeRegex().Match(input).Groups[2].Value;\n                return new CustomRange()\n                {\n                    InputStr = input,","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/nilaoda/N_m3u8DL-RE/blob/e113dee70c924ee08dae5460624909b04d84cb76/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs#L143-L179","documentation":"CommandInvoker parses a user-supplied range string (e.g. segment index ranges for --select-segments) by splitting on '-'. If the string does not contain exactly one '-' separated into two parts, the parser cannot interpret it as a range and throws ArgumentException(\"Bad format!\"). The caller's catch block converts this into a parse error entry.","triggerScenarios":"Calling the range parser (via command-line parsing of a range option) with a string like \"5\", \"1-2-3\", \"abc\", or an empty-ish string with no '-'; only 'a-b' with exactly two parts passes.","commonSituations":"Users type a single segment index instead of a range, use the wrong separator (comma, colon), copy an index list from elsewhere, or include extra dashes.","solutions":["Supply the value as START-END, e.g. \"0-100\".","Use open-ended forms like \"-100\" or \"100-\" only if supported (they still need exactly one '-')","Remove any extra '-' characters or numeric-range commas from the input.","Check the option's help text for the accepted range syntax."],"exampleFix":"// before\nvar seg = \"12\"; // single index, no dash\n// after\nvar seg = \"12-12\"; // explicit range selecting segment 12","handlingStrategy":"validation","validationCode":"var parts = input.Split('-');\nif (parts.Length != 2) throw new FormatException($\"Expected START-END, got '{input}'\");","typeGuard":"bool IsValidRange(string s) => !string.IsNullOrEmpty(s) && s.Split('-').Length == 2;","tryCatchPattern":"try { ParseRange(input); }\ncatch (ArgumentException ex) { Console.Error.WriteLine($\"Invalid range '{input}': use START-END\"); }","preventionTips":["Always pass ranges as two dash-separated integers.","Validate input format in wrapper scripts before invoking the CLI.","Add a regex check ^-?\\d+-\\d+-$ style validation on user input."],"tags":["argument-parsing","cli","range-input"],"backgroundTag":"invalid-argument-format","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"}