{"record":{"id":"6293cd0704935e0f","repo":"Tencent/matrix","slug":"exactly-one-filename-argument-is-required","errorCode":null,"errorMessage":"Exactly one filename argument is required.\n","messagePattern":"Exactly one filename argument is required\\.\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-sqlite-lint/src/lemon/lemon-gen/lemon.c","lineNumber":1422,"sourceCode":"    {OPT_FSTR, \"D\", (char*)handle_D_option, \"Define an %ifdef macro.\"},\n    {OPT_FLAG, \"g\", (char*)&rpflag, \"Print grammar without actions.\"},\n    {OPT_FLAG, \"m\", (char*)&mhflag, \"Output a makeheaders compatible file\"},\n    {OPT_FLAG, \"q\", (char*)&quiet, \"(Quiet) Don't print the report file.\"},\n    {OPT_FLAG, \"s\", (char*)&statistics,\n                                   \"Print parser stats to standard output.\"},\n    {OPT_FLAG, \"x\", (char*)&version, \"Print the version number.\"},\n    {OPT_FLAG,0,0,0}\n  };\n  int i;\n  struct lemon lem;\n\n  OptInit(argv,options,stderr);\n  if( version ){\n     printf(\"Lemon version 1.0\\n\");\n     exit(0);\n  }\n  if( OptNArgs()!=1 ){\n    fprintf(stderr,\"Exactly one filename argument is required.\\n\");\n    exit(1);\n  }\n  lem.errorcnt = 0;\n\n  /* Initialize the machine */\n  Strsafe_init();\n  Symbol_init();\n  State_init();\n  lem.argv0 = argv[0];\n  lem.filename = OptArg(0);\n  lem.basisflag = basisflag;\n  lem.has_fallback = 0;\n  lem.nconflict = 0;\n  lem.name = lem.include = lem.arg = lem.tokentype = lem.start = 0;\n  lem.vartype = 0;\n  lem.stacksize = 0;\n  lem.error = lem.overflow = lem.failure = lem.accept = lem.tokendest =\n     lem.tokenprefix = lem.outname = lem.extracode = 0;","sourceCodeStart":1404,"sourceCodeEnd":1440,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-sqlite-lint/src/lemon/lemon-gen/lemon.c#L1404-L1440","documentation":"After parsing command-line options via OptInit(), lemon requires exactly one non-option argument: the path to the grammar (.y) file. If OptNArgs() != 1 it prints 'Exactly one filename argument is required.' to stderr and exits with status 1. This is input validation of the command line, not a memory error.","triggerScenarios":"Invoking lemon with zero grammar files (e.g. 'lemon -d.'), or with two or more file arguments (e.g. 'lemon a.y b.y'), so OptNArgs() returns anything other than 1 at lemon.c:1422 in main().","commonSituations":"Build systems quoting variables that expand to multiple files; accidentally passing both a .y and a .lemon or output filename; forgetting the grammar file entirely; typo'd flags swallowing or adding positional args (e.g. an option missing its value).","solutions":["Invoke lemon with exactly one grammar file: lemon parse.y.","Check build scripts/Makefiles for variables expanding to multiple filenames; quote or restrict them.","Use lemon -h / read usage output to confirm option syntax (e.g. -d takes a directory as part of the same token).","Ensure every flag has its expected value so no intended filename is consumed as an option argument.","Filter the file list in the build recipe down to the single grammar before calling lemon."],"exampleFix":"// before (Makefile)\nlemon $(YACC_FILES)\n// after (Makefile)\nlemon $(GRAMMAR_FILE)   # GRAMMAR_FILE must expand to exactly one .y file","handlingStrategy":"validation","validationCode":"# shell: verify exactly one grammar file before calling lemon\nfiles=$(ls *.y 2>/dev/null | wc -l)\n[ \"$files\" -eq 1 ] || { echo \"need exactly one .y grammar file, found $files\"; exit 1; }\nlemon \"$1\"","typeGuard":null,"tryCatchPattern":"// wrapper in C or shell checking lemon's exit code 1 and its stderr message\nif ! lemon \"$GRAMMAR\"; then\n  echo \"lemon failed; check that exactly one grammar file was passed\" >&2\nfi","preventionTips":["Always pass exactly one .y file; never glob multiple grammars in one lemon invocation","Quote variables in build scripts so expansion can't add extra positional args","Verify option syntax with lemon -h (e.g. -d dir attaches to the flag, not a positional)","Assert file count in Makefile/CMake custom commands before invoking lemon"],"tags":["c","cli","argument-validation","parser-generator"],"backgroundTag":"missing-required-argument","analyzedSha":"3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7","analyzedAt":"2026-09-08T08:01:39.722Z","contentChangedAt":"2026-09-08T08:01:39.722Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}