{"record":{"id":"e0f4a11b68474767","repo":"Tencent/matrix","slug":"can-t-open-the-template-file-s","errorCode":null,"errorMessage":"Can't open the template file \"%s\".\n","messagePattern":"Can't open the template file \"(.+?)\"\\.\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-sqlite-lint/src/lemon/lemon-gen/lemon.c","lineNumber":3010,"sourceCode":"  }else{\n    sprintf(buf,\"%s.lt\",lemp->filename);\n  }\n  if( access(buf,004)==0 ){\n    tpltname = buf;\n  }else if( access(templatename,004)==0 ){\n    tpltname = templatename;\n  }else{\n    tpltname = pathsearch(lemp->argv0,templatename,0);\n  }\n  if( tpltname==0 ){\n    fprintf(stderr,\"Can't find the parser driver template file \\\"%s\\\".\\n\",\n    templatename);\n    lemp->errorcnt++;\n    return 0;\n  }\n  in = fopen(tpltname,\"rb\");\n  if( in==0 ){\n    fprintf(stderr,\"Can't open the template file \\\"%s\\\".\\n\",templatename);\n    lemp->errorcnt++;\n    return 0;\n  }\n  return in;\n}\n\n/* Print a #line directive line to the output file. */\nPRIVATE void tplt_linedir(out,lineno,filename)\nFILE *out;\nint lineno;\nchar *filename;\n{\n  fprintf(out,\"#line %d \\\"\",lineno);\n  while( *filename ){\n    if( *filename == '\\\\' ) putc('\\\\',out);\n    putc(*filename,out);\n    filename++;\n  }","sourceCodeStart":2992,"sourceCodeEnd":3028,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-sqlite-lint/src/lemon/lemon-gen/lemon.c#L2992-L3028","documentation":"After locating the template file (tpltname), lemon fopen()s it in \"rb\" mode; if fopen fails it prints 'Can't open the template file \"<name>\".' and aborts. Unlike error 306, the file was found but could not actually be opened for reading.","triggerScenarios":"lempar.c exists at the resolved path but lacks read permission for the current user; a dangling symlink or directory named lempar.c passes pathsearch/access checks but fopen fails; the file is deleted between lookup and open; a filesystem error (I/O error, encrypted/unmounted volume).","commonSituations":"Templates copied into the build with wrong ownership/permissions; NFS or Docker volume mount glitches; passing -T a path that resolves to a directory; race conditions in parallel builds cleaning the template directory.","solutions":["chmod a+r lempar.c (or the path given via -T) so the invoking user can read it","Verify the path is a regular readable file (file lempar.c; ls -l)","Re-copy the template from the source tree (matrix-sqlite-lint/src/lemon/lemon-gen/lempar.c)","Fix the volume mount/filesystem health if on NFS or a container mount"],"exampleFix":"// before\n-rw------- lempar.c  # owned by root, build runs as builder\n// after\nchmod 644 lempar.c","handlingStrategy":"validation","validationCode":"#!/bin/sh\nTPL=path/to/lempar.c\n[ -f \"$TPL\" ] && [ -r \"$TPL\" ] || { echo \"template not a readable file: $TPL\"; exit 1; }\nlemon -T \"$TPL\" parser.y","typeGuard":null,"tryCatchPattern":null,"preventionTips":["chmod 644 templates when staging them into build directories","Check that -T paths are regular files, not directories or dangling symlinks","Avoid parallel build steps that clean the template directory mid-run","Verify volume mounts are healthy when building in containers"],"tags":["lemon","template","file-read-failed","permissions"],"backgroundTag":"file-open-failed","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"}