{"record":{"id":"894b8b3fb9d98557","repo":"python/cpython","slug":"unknown-option-ls-n","errorCode":null,"errorMessage":"Unknown option: %ls\\n","messagePattern":"Unknown option: %ls\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"Python/getopt.c","lineNumber":117,"sourceCode":"        return -1;\n\n    if (option == L'-') {\n        // Parse long option.\n        if (*opt_ptr == L'\\0') {\n            if (_PyOS_opterr) {\n                fprintf(stderr, \"Expected long option\\n\");\n            }\n            return -1;\n        }\n        *longindex = 0;\n        const _PyOS_LongOption *opt;\n        for (opt = &longopts[*longindex]; opt->name; opt = &longopts[++(*longindex)]) {\n            if (!wcscmp(opt->name, opt_ptr))\n                break;\n        }\n        if (!opt->name) {\n            if (_PyOS_opterr) {\n                fprintf(stderr, \"Unknown option: %ls\\n\", argv[_PyOS_optind - 1]);\n            }\n            return '_';\n        }\n        opt_ptr = L\"\";\n        if (!opt->has_arg) {\n            return opt->val;\n        }\n        if (_PyOS_optind >= argc) {\n            if (_PyOS_opterr) {\n                fprintf(stderr, \"Argument expected for the %ls options\\n\",\n                        argv[_PyOS_optind - 1]);\n            }\n            return '_';\n        }\n        _PyOS_optarg = argv[_PyOS_optind++];\n        return opt->val;\n    }\n","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Python/getopt.c#L99-L135","documentation":"Command-line parse error from CPython's internal getopt (Python/getopt.c): an argument of the form '--name' did not match any entry in the interpreter's long-option table (the wcscmp loop over longopts found no match). It prints 'Unknown option: <arg>' and returns '_', so the interpreter reports the unrecognized option and exits.","triggerScenarios":"Passing a long flag python does not define, e.g. `python3 --verbose=2` where no '=' form is supported, `--version3`, or flags from another interpreter (like `--check`); also typos such as `--versio`.","commonSituations":"Assuming GNU-style abbreviations or flags from other tools work on python; scripts porting from `node`/`ruby` idioms; CI scripts with a typo'd flag failing immediately; using options that only exist in newer/older Python versions.","solutions":["Check the flag exists: `python3 --help` lists valid options","Fix the typo or drop unsupported '='-forms (use `python3 -W default`, `-X dev`, etc.)","If the flag is version-specific, guard the command per interpreter version","For your own argument parsing, use argparse inside the script rather than hoping python parses custom flags"],"exampleFix":"# before\npython3 --verbose2 script.py   # Unknown option\n\n# after\npython3 -v script.py             # valid short option\n# or\npython3 -X dev script.py         # use documented long forms via -X","handlingStrategy":"validation","validationCode":"# shell: verify flags before running\n# for f in --check --verbose2; do python3 \"$f\" --help >/dev/null 2>&1 || { echo \"bad flag: $f\"; exit 1; }; done 2>/dev/null || true\n# simplest: python3 --help >/dev/null && python3 -c 'import sys; sys.exit(0)'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Cross-check flags against `python3 --help` before baking them into scripts","Remember python long options do not support GNU abbreviation","Version-gate flags that only exist in newer CPython releases","Handle your program's own flags with argparse inside the script, not via interpreter options"],"tags":["cli","getopt","command-line","unknown-option","cpython"],"backgroundTag":null,"analyzedSha":"bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6","analyzedAt":"2026-08-14T22:01:13.976Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}