{"record":{"id":"f9fa60072e4dc1e7","repo":"nilaoda/N_m3u8DL-RE","slug":"parse-argument-key-failed","errorCode":null,"errorMessage":"Parse Argument [{key}] failed!","messagePattern":"Parse Argument \\[(.+?)\\] failed!","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/N_m3u8DL-RE/CommandLine/ComplexParamParser.cs","lineNumber":58,"sourceCode":"                    result.Append(chars[i]);\n                }\n            }\n\n            var resultStr = result.ToString().Trim();\n\n            // 仅去除成对的首尾引号, 保留值内部的引号(例如文件名中的撇号: What's Next)\n            if (resultStr.Length >= 2\n                && (resultStr[0] == '\\\"' || resultStr[0] == '\\'')\n                && resultStr[^1] == resultStr[0])\n            {\n                resultStr = resultStr[1..^1];\n            }\n\n            return resultStr;\n        }\n        catch (Exception)\n        {\n            throw new ArgumentException($\"Parse Argument [{key}] failed!\");\n        }\n    }\n}","sourceCodeStart":40,"sourceCodeEnd":61,"githubUrl":"https://github.com/nilaoda/N_m3u8DL-RE/blob/e113dee70c924ee08dae5460624909b04d84cb76/src/N_m3u8DL-RE/CommandLine/ComplexParamParser.cs#L40-L61","documentation":"ComplexParamParser.GetValue looks up a key in the parsed complex-parameter string and throws ArgumentException(\"Parse Argument [{key}] failed!\") when the internal parsing/formatting of the value fails for any reason (the original exception is discarded). Callers use it to extract values from options like headers or custom params.","triggerScenarios":"Calling GetValue(key) on an input string whose structure the parser cannot handle — unbalanced quotes/apostrophes, malformed key=value pairs, or a key whose value block fails parsing — any internal exception is wrapped into this error.","commonSituations":"Users pass header/param strings with unescaped apostrophes or double quotes (e.g. \"It's here\" or nested quotes), or omit the '=' separator, when configuring headers or muxer options.","solutions":["Escape or remove unbalanced apostrophes/double quotes in the value.","Ensure each pair is in key=value form separated by the expected delimiter.","Print the raw input string and check it manually for stray characters.","Wrap GetValue in try/catch and fall back to the raw string if parsing fails."],"exampleFix":"// before\nvar v = parser.GetValue(\"header\"); // throws on malformed input\n// after\ntry { var v = parser.GetValue(\"header\"); }\ncatch (ArgumentException) { /* use raw fallback */ }","handlingStrategy":"try-catch","validationCode":"if (string.IsNullOrWhiteSpace(input) || !input.Contains('=')) throw new FormatException(\"Complex param must contain key=value pairs\");","typeGuard":"bool LooksParseable(string s) => s.Split(',').All(p => p.Split('=').Length == 2);","tryCatchPattern":"try { value = parser.GetValue(key); }\ncatch (ArgumentException) { value = rawFallback; }","preventionTips":["Escape apostrophes and double quotes in option values.","Keep every pair in key=value form with the expected separator.","Test complex option strings in isolation before adding them to scripts."],"tags":["argument-parsing","cli"],"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"}