{"record":{"id":"a3f1c245eb6018f9","repo":"slint-ui/slint","slug":"write-err","errorCode":null,"errorMessage":"write {}: {err}","messagePattern":"write (.+?): (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"api/node/build.rs","lineNumber":680,"sourceCode":"/// never sees them and they need no license header.\nfn generated_header(sources: &[&str]) -> String {\n    format!(\n        \"// AUTO-GENERATED by api/node/build.rs from {}. Do not edit.\\n\\n\",\n        sources.join(\"\\n// \")\n    )\n}\n\n/// Write `contents` only if it differs, so we don't invalidate downstream builds, and watch\n/// the result so it regenerates when edited or removed by hand.\nfn write_if_changed(path: &std::path::Path, contents: &str) {\n    println!(\"cargo:rerun-if-changed={}\", path.display());\n    let dir = path.parent().expect(\"generated file has a parent directory\");\n    std::fs::create_dir_all(dir).unwrap_or_else(|err| panic!(\"create {}: {err}\", dir.display()));\n    let needs_write =\n        std::fs::read_to_string(path).map(|existing| existing != contents).unwrap_or(true);\n    if needs_write {\n        std::fs::write(path, contents)\n            .unwrap_or_else(|err| panic!(\"write {}: {err}\", path.display()));\n    }\n}\n","sourceCodeStart":662,"sourceCodeEnd":683,"githubUrl":"https://github.com/slint-ui/slint/blob/bb937076de3f7919766c1f25e2e969367cf77e9a/api/node/build.rs#L662-L683","documentation":"The Node.js binding build script fails when it cannot write the generated module file even though the directory exists. `write_if_changed` compares existing content and writes only on difference; `std::fs::write` failing panics with this message. The generated code (language module / window event module) cannot be produced, aborting the build.","triggerScenarios":"`std::fs::write(path, contents)` returns an error during `write_if_changed` — read-only file with the target name, permission loss between create_dir_all and write, disk full, or the target path is a directory.","commonSituations":"Generated file left owned by root from a previous sudo build; antivirus/editor locking the file on Windows; ENOSPC during long builds; a directory accidentally created at the generated file's path.","solutions":["Fix permissions/ownership of the generated file path (e.g. chown the target dir back to the build user)","Check disk space; the write can fail on ENOSPC","Remove any directory or read-only file occupying the generated file's path","Run `cargo clean` and rebuild as a single non-root user"],"exampleFix":"// before: stale root-owned generated file\n# ls -l target/.../gen/js.rs  -> owned by root\n// after\nsudo rm -f target/.../gen/js.rs && cargo build","handlingStrategy":"validation","validationCode":"fs.accessSync(targetFile, fs.constants.W_OK);\nif (fs.existsSync(targetFile) && fs.statSync(targetFile).isDirectory()) throw new Error('path is a directory');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never run builds with sudo; chown target/ back if you did","Watch for AV/editor locks on generated files during dev loops","Monitor free disk space in CI"],"tags":["build-script","filesystem","codegen","nodejs"],"backgroundTag":"file-write-failed","analyzedSha":"bb937076de3f7919766c1f25e2e969367cf77e9a","analyzedAt":"2026-09-16T01:37:20.251Z","contentChangedAt":"2026-09-16T01:37:20.251Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}