nilaoda/N_m3u8DL-RE · error · ArgumentException
Invalid Speed Limit
Error message
Invalid Speed Limit: {input} What it means
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.
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 ','.
Example fix
// before --speed-limit "10Mbps" // after --speed-limit "10M"
Defensive patterns
Strategy: validation
Validate before calling
// validate the speed limit against the same pattern the CLI uses
static bool IsValidSpeedLimit(string input) =>
System.Text.RegularExpressions.Regex.IsMatch(
(input ?? "").ToUpperInvariant(), @"^([0-9]+(?:\.[0-9]+)?)([KM])$");
if (!IsValidSpeedLimit(userInput)) throw new ArgumentException($"Invalid Speed Limit: {userInput}"); Try / catch
try { cli.Parse(args); }
catch (ArgumentException ex) when (ex.Message.StartsWith("Invalid Speed Limit")) {
Console.Error.WriteLine($"{ex.Message} -- use format like '10M' or '512K' (bytes/s)");
Environment.Exit(1);
} Prevention
- 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 ','.
When it happens
Trigger: 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.
Common situations: 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').
Understand the failure class
Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.
Related errors
- MuxAfterDone disabled, MuxImports not allowed!
- Mp4 box names must be 4 characters long
- Bad format!
- must be valid 16-byte HEX or Base64. Input string
- Input must be KEY or KID:KEY format.
AI-assisted analysis of nilaoda/N_m3u8DL-RE@e113dee70c (2026-09-13).
Data as JSON: /api/errors/31f6fec59e6b84b1.
Report an issue: GitHub.
Appendix: source
Thrown at src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs:130
private static readonly Option<StreamFilter?> AudioFilter = new("-sa", "--select-audio") { HelpName = "OPTIONS", Description = ResString.cmd_selectAudio, CustomParser = ParseStreamFilter };
private static readonly Option<StreamFilter?> SubtitleFilter = new("-ss", "--select-subtitle") { HelpName = "OPTIONS", Description = ResString.cmd_selectSubtitle, CustomParser = ParseStreamFilter };
private static readonly Option<StreamFilter?> DropVideoFilter = new("-dv", "--drop-video") { HelpName = "OPTIONS", Description = ResString.cmd_dropVideo, CustomParser = ParseStreamFilter };
private static readonly Option<StreamFilter?> DropAudioFilter = new("-da", "--drop-audio") { HelpName = "OPTIONS", Description = ResString.cmd_dropAudio, CustomParser = ParseStreamFilter };
private static readonly Option<StreamFilter?> DropSubtitleFilter = new("-ds", "--drop-subtitle") { HelpName = "OPTIONS", Description = ResString.cmd_dropSubtitle, CustomParser = ParseStreamFilter };
/// <summary>
/// 解析下载速度限制
/// </summary>
/// <param name="result"></param>
/// <returns></returns>
private static long? ParseSpeedLimit(ArgumentResult result)
{
var input = result.Tokens[0].Value.ToUpper();
try
{
var reg = SpeedStrRegex();
if (!reg.IsMatch(input)) throw new ArgumentException($"Invalid Speed Limit: {input}");
var number = double.Parse(reg.Match(input).Groups[1].Value);
if (reg.Match(input).Groups[2].Value == "M")
return (long)(number * 1024 * 1024);
return (long)(number * 1024);
}
catch (Exception)
{
result.AddError("error in parse SpeedLimit: " + input);
return null;
}
}
/// <summary>
/// 解析用户定义的下载范围
/// </summary>
/// <param name="result"></param>
/// <returns></returns>View on GitHub (pinned to e113dee70c)