bazelbuild/bazel · error

Failed to create " STRING_FORMAT ": %s\n

Error message

Failed to create " STRING_FORMAT ": %s\n

What it means

launcher_maker creates the output executable (argv[3]) with std::ofstream in binary mode; if the stream is bad it prints the output path plus strerror(errno) and exits 1. The output file could not be created — typically a missing parent directory, a read-only target, or the file being locked by another Windows process.

Source

Thrown at src/tools/launcher/launcher_maker.cc:80

int main(int argc, char** argv) {
  if (argc < 4) {
    fprintf(stderr, "Expected 3 arguments, got %d\n", argc);
    return 1;
  }

  STRING_TYPE launcher_path = convert_path(argv[1]);
  STRING_TYPE info_params = convert_path(argv[2]);
  STRING_TYPE output_path = convert_path(argv[3]);

  std::ifstream src(launcher_path.c_str(), std::ios::binary);
  if (!src.good()) {
    fprintf(stderr, "Failed to open " STRING_FORMAT ": %s\n",
            launcher_path.c_str(), strerror(errno));
    return 1;
  }
  std::ofstream dst(output_path.c_str(), std::ios::binary);
  if (!dst.good()) {
    fprintf(stderr, "Failed to create " STRING_FORMAT ": %s\n",
            output_path.c_str(), strerror(errno));
    return 1;
  }
  dst << src.rdbuf();

  std::ifstream info_file(info_params.c_str());
  if (!info_file.good()) {
    fprintf(stderr, "Failed to open " STRING_FORMAT ": %s\n",
            info_params.c_str(), strerror(errno));
    return 1;
  }
  int64_t bytes = 0;
  std::string line;
  while (std::getline(info_file, line)) {
    dst << line;
    bytes += line.length();
    dst << '\0';
    bytes++;

View on GitHub (pinned to e6e199d060)

Solutions

  1. Stop any process running the target launcher exe, then rebuild.
  2. Create/verify the parent directory and free disk space.
  3. Add the output tree to antivirus exclusions.
  4. If a custom rule declared an output outside bazel-out, fix it to declare outputs under the package's standard output tree.

Example fix

# before: previous launcher still running locks out.exe
taskkill /IM my-launcher.exe /F 2>nul
bazel build //tools:my-launcher   # after: recreates output cleanly
Defensive patterns

Strategy: validation

Validate before calling

// ensure the output's parent directory exists and the target is not locked
std::filesystem::create_directories(std::filesystem::path(out).parent_path());
// On Windows: attempt a probe open to detect a lock before the action runs
FILE *probe = _wfopen(out.c_str(), L"wb");
if (!probe) { /* report 'output locked' */ return false; } fclose(probe);

Prevention

When it happens

Trigger: The rule's declared output lives in a directory Bazel did not create (e.g. an exec-root path removed by cleanup); an existing output exe is running or locked (Windows locks executing images); insufficient permissions or full disk at the destination.

Common situations: Rebuilding while the previously built launcher .exe is still executing; antivirus scanning the freshly created exe and locking it; disk-full CI agents.

Related errors


AI-assisted analysis of bazelbuild/bazel@e6e199d060 (2026-08-14). Data as JSON: /api/errors/014690ed9cd47433. Report an issue: GitHub.