{"record":{"id":"014690ed9cd47433","repo":"bazelbuild/bazel","slug":"failed-to-create-string-format-s-n","errorCode":null,"errorMessage":"Failed to create \" STRING_FORMAT \": %s\\n","messagePattern":"Failed to create \" STRING_FORMAT \": (.+?)\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/tools/launcher/launcher_maker.cc","lineNumber":80,"sourceCode":"int main(int argc, char** argv) {\n  if (argc < 4) {\n    fprintf(stderr, \"Expected 3 arguments, got %d\\n\", argc);\n    return 1;\n  }\n\n  STRING_TYPE launcher_path = convert_path(argv[1]);\n  STRING_TYPE info_params = convert_path(argv[2]);\n  STRING_TYPE output_path = convert_path(argv[3]);\n\n  std::ifstream src(launcher_path.c_str(), std::ios::binary);\n  if (!src.good()) {\n    fprintf(stderr, \"Failed to open \" STRING_FORMAT \": %s\\n\",\n            launcher_path.c_str(), strerror(errno));\n    return 1;\n  }\n  std::ofstream dst(output_path.c_str(), std::ios::binary);\n  if (!dst.good()) {\n    fprintf(stderr, \"Failed to create \" STRING_FORMAT \": %s\\n\",\n            output_path.c_str(), strerror(errno));\n    return 1;\n  }\n  dst << src.rdbuf();\n\n  std::ifstream info_file(info_params.c_str());\n  if (!info_file.good()) {\n    fprintf(stderr, \"Failed to open \" STRING_FORMAT \": %s\\n\",\n            info_params.c_str(), strerror(errno));\n    return 1;\n  }\n  int64_t bytes = 0;\n  std::string line;\n  while (std::getline(info_file, line)) {\n    dst << line;\n    bytes += line.length();\n    dst << '\\0';\n    bytes++;","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/src/tools/launcher/launcher_maker.cc#L62-L98","documentation":"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.","triggerScenarios":"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.","commonSituations":"Rebuilding while the previously built launcher .exe is still executing; antivirus scanning the freshly created exe and locking it; disk-full CI agents.","solutions":["Stop any process running the target launcher exe, then rebuild.","Create/verify the parent directory and free disk space.","Add the output tree to antivirus exclusions.","If a custom rule declared an output outside bazel-out, fix it to declare outputs under the package's standard output tree."],"exampleFix":"# before: previous launcher still running locks out.exe\ntaskkill /IM my-launcher.exe /F 2>nul\nbazel build //tools:my-launcher   # after: recreates output cleanly","handlingStrategy":"validation","validationCode":"// ensure the output's parent directory exists and the target is not locked\nstd::filesystem::create_directories(std::filesystem::path(out).parent_path());\n// On Windows: attempt a probe open to detect a lock before the action runs\nFILE *probe = _wfopen(out.c_str(), L\"wb\");\nif (!probe) { /* report 'output locked' */ return false; } fclose(probe);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Stop running instances of the launcher exe before rebuilding (Windows locks executing images).","Declare outputs inside bazel-out so Bazel creates parent directories.","Exclude build output from antivirus scanning."],"tags":["windows","launcher","file-io","ofstream","file-lock"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}