{"record":{"id":"6eb4c6d8b3bded97","repo":"wasmerio/wasmer","slug":"cannot-create-debug-directory","errorCode":null,"errorMessage":"cannot create debug directory: {}","messagePattern":"cannot create debug directory: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/compiler-cranelift/src/config.rs","lineNumber":49,"sourceCode":"    /// Creates a new instance of `CraneliftCallbacks` with the specified debug directory.\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 where the debug files are written.\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    /// Writes the pre-optimization intermediate representation to a debug file.\n    pub fn preopt_ir(&self, kind: &CompiledKind, module_hash: &Option<String>, mem_buffer: &[u8]) {\n        let mut path = self.base_path(module_hash);\n        path.push(function_kind_to_filename(kind, \".preopt.clif\"));\n        let mut file =\n            File::create(path).expect(\"Error while creating debug file from Cranelift IR\");\n        file.write_all(mem_buffer).unwrap();\n    }\n\n    /// Writes the object file memory buffer to a debug file.\n    pub fn obj_memory_buffer(\n        &self,\n        kind: &CompiledKind,\n        module_hash: &Option<String>,\n        mem_buffer: &[u8],","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/wasmerio/wasmer/blob/8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5/lib/compiler-cranelift/src/config.rs#L31-L67","documentation":"CraneliftCompilerConfig's base_path creates (create_dir_all) the debug output directory — optionally under a module hash subdirectory — used to dump preopt IR, object files, and asm during compilation. If directory creation fails (permissions, read-only filesystem, path conflicts), it panics. This only happens when debug output is enabled, so it never affects normal compilation.","triggerScenarios":"Compilation with Cranelift debug features enabled where base_path is called by preopt_ir, obj_memory_buffer, or asm_memory_buffer and std::fs::create_dir_all fails: debug_dir points somewhere non-writable/nonexistent-parent, or a file exists at the path.","commonSituations":"Enabling Cranelift debug dumps (WASMER_CRANELIFT_DEBUG_DIR / config debug_dir) in production containers with read-only rootfs; permission mismatch between the running user and the configured debug dir; module-hash subdirectory colliding with an existing regular file.","solutions":["Point the Cranelift debug_dir at a directory the process can write (e.g. /tmp/cranelift-debug or a mounted volume).","Disable debug output (remove the debug dir setting / unset the debug env var) if dumps aren't needed.","Check the path: ensure no regular file occupies the target path and parent directories are creatable.","Run the compiler as a user with write permission on the configured directory."],"exampleFix":"// before\nexport WASMER_CRANELIFT_DEBUG_DIR=/var/lib/wasmer/debug # read-only fs\n// after\nexport WASMER_CRANELIFT_DEBUG_DIR=/tmp/wasmer-debug && mkdir -p /tmp/wasmer-debug","handlingStrategy":"validation","validationCode":"// Before enabling Cranelift debug dumps, ensure the dir is writable:\nuse std::fs;\nfn debug_dir_usable(dir: &std::path::Path) -> bool {\n    fs::create_dir_all(dir).is_ok() && fs::metadata(dir).map(|m| m.is_dir()).unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Point debug_dir at writable tmp/volume paths, especially in containers.","Disable debug dumps in production builds.","Ensure no regular file occupies the configured debug dir path."],"tags":["rust","panic","cranelift","filesystem","permissions","debug"],"backgroundTag":"directory-create-failed","analyzedSha":"8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5","analyzedAt":"2026-09-01T23:06:31.009Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}