bazelbuild/bazel · error

Failed to open " STRING_FORMAT

Error message

Failed to open " STRING_FORMAT ": %s\n

What it means

launcher_maker opens argv[1] — the base launcher binary shipped with Bazel — with std::ifstream in binary mode; if the stream is not good() it prints the path (wide-string aware via STRING_FORMAT '%ls' on Windows) plus strerror(errno) and exits 1. It means the launcher template file does not exist or is not readable at the moment the action runs.

Solutions

  1. Verify the printed path exists and is readable (type <path> on Windows).
  2. Check the errno text: 'No such file or directory' → fix the argument; 'Permission denied' → fix ACLs or AV exclusions.
  3. Ensure nothing deletes runfiles/output-base content concurrently (bazel clean while a build runs).
  4. For custom rules, use a files= dep on the launcher so Bazel materializes it before the action.
Defensive patterns

Strategy: validation

Validate before calling

// verify the launcher input exists and is readable before running the action
struct stat st;
if (stat(launcher_path.c_str(), &st) != 0 || !(st.st_mode & S_IREAD)) {
  fprintf(stderr, "missing/unreadable launcher: %s\n", launcher_path.c_str());
  return 1;
}

Prevention

When it happens

Trigger: The launcher binary path argument points to a missing/moved file; the file exists but permissions deny read; the path contains characters mishandled by the shell so it resolves to a nonexistent name.

Common situations: Custom rules passing a wrong launcher location; antivirus quarantining the launcher exe; output base pruned mid-build by an external cleaner.

Related errors


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

Appendix: source

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

#define STRING_TYPE std::string
#define STRING_FORMAT "%s"
std::string convert_path(char* path) { return path; }

#endif  // _WIN32

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;

View on GitHub (pinned to e6e199d060)