nilaoda/N_m3u8DL-RE · error · ArgumentException
Bad format!
Error message
Bad format!
What it means
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.
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.
Example fix
// before var seg = "12"; // single index, no dash // after var seg = "12-12"; // explicit range selecting segment 12
Defensive patterns
Strategy: validation
Validate before calling
var parts = input.Split('-');
if (parts.Length != 2) throw new FormatException($"Expected START-END, got '{input}'"); Type guard
bool IsValidRange(string s) => !string.IsNullOrEmpty(s) && s.Split('-').Length == 2; Try / catch
try { ParseRange(input); }
catch (ArgumentException ex) { Console.Error.WriteLine($"Invalid range '{input}': use START-END"); } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Parse Argument [ ] failed!
- Invalid Speed Limit
- must be valid 16-byte HEX or Base64. Input string
- Input must be KEY or KID:KEY format.
- MuxAfterDone disabled, MuxImports not allowed!
AI-assisted analysis of nilaoda/N_m3u8DL-RE@e113dee70c (2026-09-13).
Data as JSON: /api/errors/e3953dd6774390a3.
Report an issue: GitHub.
Appendix: source
Thrown at src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs:161
/// <summary>
/// 解析用户定义的下载范围
/// </summary>
/// <param name="result"></param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
private static CustomRange? ParseCustomRange(ArgumentResult result)
{
var input = result.Tokens[0].Value;
// 支持的种类 0-100; 01:00:00-02:30:00; -300; 300-; 05:00-; -03:00;
try
{
if (string.IsNullOrEmpty(input))
return null;
var arr = input.Split('-');
if (arr.Length != 2)
throw new ArgumentException("Bad format!");
if (input.Contains(':'))
{
return new CustomRange()
{
InputStr = input,
StartSec = arr[0] == "" ? 0 : OtherUtil.ParseDur(arr[0]).TotalSeconds,
EndSec = arr[1] == "" ? double.MaxValue : OtherUtil.ParseDur(arr[1]).TotalSeconds,
};
}
if (RangeRegex().IsMatch(input))
{
var left = RangeRegex().Match(input).Groups[1].Value;
var right = RangeRegex().Match(input).Groups[2].Value;
return new CustomRange()
{
InputStr = input,View on GitHub (pinned to e113dee70c)