Tencent/matrix · error
Can't open the template file
Error message
Can't open the template file "%s".
What it means
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.
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
Example fix
// before -rw------- lempar.c # owned by root, build runs as builder // after chmod 644 lempar.c
Defensive patterns
Strategy: validation
Validate before calling
#!/bin/sh
TPL=path/to/lempar.c
[ -f "$TPL" ] && [ -r "$TPL" ] || { echo "template not a readable file: $TPL"; exit 1; }
lemon -T "$TPL" parser.y Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.
Related errors
- Can't open file " ".
- Can't find the parser driver template file
- ---Create directory '<outputFile.getAbsolutePath()>' failed!
- Empty grammar.
- parsing conflicts.
AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08).
Data as JSON: /api/errors/e0f4a11b68474767.
Report an issue: GitHub.
Appendix: source
Thrown at matrix/matrix-android/matrix-sqlite-lint/src/lemon/lemon-gen/lemon.c:3010
}else{
sprintf(buf,"%s.lt",lemp->filename);
}
if( access(buf,004)==0 ){
tpltname = buf;
}else if( access(templatename,004)==0 ){
tpltname = templatename;
}else{
tpltname = pathsearch(lemp->argv0,templatename,0);
}
if( tpltname==0 ){
fprintf(stderr,"Can't find the parser driver template file \"%s\".\n",
templatename);
lemp->errorcnt++;
return 0;
}
in = fopen(tpltname,"rb");
if( in==0 ){
fprintf(stderr,"Can't open the template file \"%s\".\n",templatename);
lemp->errorcnt++;
return 0;
}
return in;
}
/* Print a #line directive line to the output file. */
PRIVATE void tplt_linedir(out,lineno,filename)
FILE *out;
int lineno;
char *filename;
{
fprintf(out,"#line %d \"",lineno);
while( *filename ){
if( *filename == '\\' ) putc('\\',out);
putc(*filename,out);
filename++;
}View on GitHub (pinned to 3b8293bd65)