{"record":{"id":"5bd34f6b53bd2df3","repo":"wasmerio/wasmer","slug":"cannot-create-debug-directory-5bd34f","errorCode":null,"errorMessage":"cannot create debug directory: {}","messagePattern":"cannot create debug directory: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/compiler-llvm/src/config.rs","lineNumber":54,"sourceCode":"impl LLVMCallbacks {\n    pub fn new(debug_dir: PathBuf) -> Result<Self, io::Error> {\n        // Create the debug dir in case it doesn't exist\n        std::fs::create_dir_all(&debug_dir)?;\n        Ok(Self { debug_dir })\n    }\n\n    /// Returns the debug directory used to dump compilation artifacts.\n    pub fn debug_dir(&self) -> &PathBuf {\n        &self.debug_dir\n    }\n\n    fn base_path(&self, module_hash: &Option<String>) -> PathBuf {\n        let mut path = self.debug_dir.clone();\n        if let Some(hash) = module_hash {\n            path.push(hash);\n        }\n        std::fs::create_dir_all(&path)\n            .unwrap_or_else(|_| panic!(\"cannot create debug directory: {}\", path.display()));\n        path\n    }\n\n    pub fn preopt_ir(\n        &self,\n        kind: &CompiledKind,\n        module_hash: &Option<String>,\n        module: &InkwellModule,\n    ) {\n        let mut path = self.base_path(module_hash);\n        path.push(function_kind_to_filename(kind, \".preopt.ll\"));\n        module\n            .print_to_file(&path)\n            .expect(\"Error while dumping pre optimized LLVM IR\");\n    }\n    pub fn postopt_ir(\n        &self,\n        kind: &CompiledKind,","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/wasmerio/wasmer/blob/8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5/lib/compiler-llvm/src/config.rs#L36-L72","documentation":"base_path creates the directory where LLVM debug artifacts (pre/post-optimization IR, object files, asm) are dumped when debug directives are enabled. If std::fs::create_dir_all fails (permissions, path collisions, invalid path characters), the code panics with the path it could not create. It only runs when debug output is configured via the LLVM debug builder settings.","triggerScenarios":"Enabling LLVM debug output (e.g. `set_debug_info`/debug_dir config on the LLVM builder) where the configured debug_dir cannot be created: read-only filesystem, insufficient permissions, a non-directory file already exists at the path (or at the module-hash subpath), or an invalid path for the OS.","commonSituations":"Pointing debug_dir at /root-owned or read-only paths in containers; a stale regular file occupying the hash subdirectory; running the compiler as an unprivileged user while debug_dir points into a privileged location; disk full or path containing characters invalid on Windows.","solutions":["Ensure the configured debug_dir exists and is writable by the process user, or point it at a temp dir the process can create (e.g. std::env::temp_dir()).","Remove/replace any non-directory file that occupies the debug_dir path or its module-hash subpath.","Run the compilation with sufficient filesystem permissions (fix user/ACL, mount writable volume).","If debug artifacts are not needed, disable the LLVM debug output options so base_path is never called."],"exampleFix":"// before\nlet builder = LLVMBuilder::new().debug(true).debug_dir(\"/var/log/llvm-dbg\".into());\n// after\nstd::fs::create_dir_all(\"/tmp/wasmtime-llvm-dbg\").expect(\"create debug dir\");\nlet builder = LLVMBuilder::new().debug(true).debug_dir(\"/tmp/wasmtime-llvm-dbg\".into());","handlingStrategy":"validation","validationCode":"// Validate the debug dir before configuring the LLVM builder\nlet dir = std::path::Path::new(\"/tmp/wasmtime-llvm-dbg\");\nstd::fs::create_dir_all(dir).expect(\"debug dir must be creatable and writable\");\nassert!(dir.is_dir(), \"debug dir must not be an existing regular file\");","typeGuard":null,"tryCatchPattern":"// Panics cannot be caught with std::panic::catch_unwind (no UnwindSafe guarantee on builder internals);\n// prefer validating the dir up front:\nlet result = std::panic::catch_unwind(|| compile_with_debug_dir(&path));\nmatch result {\n    Ok(m) => m,\n    Err(_) => { eprintln!(\"debug dir unusable; disable LLVM debug output\"); compile_without_debug()? }\n}","preventionTips":["Always create_dir_all and check writability of the debug dir before enabling LLVM debug output.","Point debug_dir at a per-process temp directory instead of system paths.","Ensure no regular file occupies the debug_dir or its hash subpaths.","Disable debug IR/asm dumps in production builds."],"tags":["panic","filesystem","io","llvm","debug-config"],"backgroundTag":"cannot-create-directory","analyzedSha":"8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5","analyzedAt":"2026-09-01T23:06:31.009Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}