nodejs/node · error

%s: could not open output file %s\n

Error message

%s: could not open output file %s\n

What it means

After successfully opening the input, convert() opens the output with std::ofstream::open and checks is_open(). Failure means the destination path cannot be written. Unlike the input case, it does NOT call cleanup() here (output may simply be absent), and returns 1.

Source

Thrown at deps/icu-small/source/tools/escapesrc/escapesrc.cpp:385

int convert(const std::string &infile, const std::string &outfile) {
  fprintf(stderr, "escapesrc: %s -> %s\n", infile.c_str(), outfile.c_str());

  std::ifstream inf;
  
  inf.open(infile.c_str(), std::ios::in);

  if(!inf.is_open()) {
    fprintf(stderr, "%s: could not open input file %s\n", prog.c_str(), infile.c_str());
    cleanup(outfile);
    return 1;
  }

  std::ofstream outf;

  outf.open(outfile.c_str(), std::ios::out);

  if(!outf.is_open()) {
    fprintf(stderr, "%s: could not open output file %s\n", prog.c_str(), outfile.c_str());
    return 1;
  }

  // TODO: any platform variations of #line?
  outf << "#line 1 \"" << infile << "\"" << '\n';

  int no = 0;
  std::string linestr;
  while( getline( inf, linestr)) {
    no++;
    if(fixLine(no, linestr)) {
      goto fail;
    }
    outf << linestr << '\n';
  }

  if(inf.eof()) {
    return 0;

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Ensure the output's parent directory exists and is writable (create it in the build rule with mkdir -p).
  2. Check disk space and quota on the destination volume.
  3. Remove or chmod any stale read-only file occupying the output path.
Defensive patterns

Strategy: validation

Validate before calling

import os
outdir = os.path.dirname(outfile) or '.'
if not os.path.isdir(outdir) or not os.access(outdir, os.W_OK):
    raise PermissionError(f'escapesrc output dir not writable: {outdir}')

Prevention

When it happens

Trigger: outf.open(outfile) fails: the parent directory does not exist, the path is a directory, the volume is read-only or full, or the caller lacks write permission.

Common situations: Destination directory not created by the build (missing mkdir -p step); output redirected to a path the build user cannot write; disk/quota full in CI; a leftover read-only file at the output path.

Related errors


AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13). Data as JSON: /api/errors/c85b9315cd5f0046. Report an issue: GitHub.