{"record":{"id":"5a97ae5da512bb62","repo":"dbt-labs/dbt-core","slug":"failed-to-write-file-e","errorCode":null,"errorMessage":"Failed to write file: {e}","messagePattern":"Failed to write file: (.+?)","errorType":"exception","errorClass":"minijinja::Error (InvalidOperation)","httpStatus":null,"severity":"error","filePath":"crates/dbt-jinja-utils/src/phases/run/run_node_context.rs","lineNumber":711,"sourceCode":"            ));\n        }\n\n        // Extract payload from args\n        let payload = match args[0].as_str() {\n            Some(s) => s,\n            None => {\n                return Err(Error::new(\n                    ErrorKind::InvalidOperation,\n                    \"Failed to convert payload to string\".to_string(),\n                ));\n            }\n        };\n\n        // Write the file\n        match write_file(&self.run_file_path, &self.resource_type, payload) {\n            Ok(_) => {}\n            Err(e) => {\n                return Err(Error::new(\n                    ErrorKind::InvalidOperation,\n                    format!(\"Failed to write file: {e}\"),\n                ));\n            }\n        }\n\n        // Return empty string on success\n        Ok(MinijinjaValue::from(\"\"))\n    }\n}\n\n/// Write a file to disk\nfn write_file(full_path: &Path, resource_type: &str, payload: &str) -> Result<(), Error> {\n    // Check if model is a Macro or SourceDefinition\n    if resource_type == \"macro\" || resource_type == \"source\" {\n        return Err(Error::new(\n            ErrorKind::InvalidOperation,\n            \"Macros and sources cannot be written to disk\",","sourceCodeStart":693,"sourceCodeEnd":729,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-jinja-utils/src/phases/run/run_node_context.rs#L693-L729","documentation":"write() wraps the underlying filesystem write in write_file(); if that helper returns an OS-level error (permissions, invalid path, disk full), the io error is wrapped into this message including the path context and original error text.","triggerScenarios":"write() targets a path in the target/ directory that cannot be written: read-only filesystem, permission denied, path too long, or the write_file helper itself returned an error not otherwise specialized.","commonSituations":"Running in containers where target/ is mounted read-only; disk quota exceeded; target path colliding with a file owned by another user after switching run users.","solutions":["Read the wrapped OS error in the message and fix the underlying cause (permissions, disk space, read-only mount).","Ensure the process user has write access to the target/ directory tree.","Clear or recreate the target/ directory if it contains files owned by another user.","Check available disk space with df and clean up old target artifacts."],"exampleFix":"// before\n# running as user without write access to target/\n// after\nchmod -R u+w target/ || chown -R dbtuser:dbtgroup target/","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match write_file(&path, &rt, payload) {\n    Ok(_) => (),\n    Err(e) if e.to_string().contains(\"Failed to write file\") => {\n        // inspect wrapped io error; check permissions/disk space before failing the run\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Ensure the dbt process user owns or can write to the target/ directory.","Monitor disk space in CI runners before long runs.","Avoid read-only mounts on --target-path directories."],"tags":["filesystem","io","file-write","dbt"],"backgroundTag":"file-write-failed","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}