{"record":{"id":"d79fad761904ebe1","repo":"facebook/flow","slug":"mkdirp-mkdir-failed","errorCode":null,"errorMessage":"mkdirp: mkdir {} failed: {}","messagePattern":"mkdirp: mkdir (.+?) failed: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rust_port/crates/flow_common/src/files.rs","lineNumber":1360,"sourceCode":"        [first_part, rest @ ..]\n            if format!(\"{}{}\", first_part, std::path::MAIN_SEPARATOR) == path_prefix =>\n        {\n            rest\n        }\n        _ => &parts,\n    };\n    parts.iter().fold(path_prefix, |path_str, part| {\n        let new_path_str = Path::new(&path_str)\n            .join(part)\n            .to_string_lossy()\n            .into_owned();\n        #[cfg(unix)]\n        {\n            use std::os::unix::fs::DirBuilderExt;\n            match std::fs::DirBuilder::new().mode(_perm).create(&new_path_str) {\n                Ok(()) => {}\n                Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => {}\n                Err(e) => panic!(\"mkdirp: mkdir {} failed: {}\", new_path_str, e),\n            }\n        }\n        #[cfg(not(unix))]\n        {\n            match std::fs::create_dir(&new_path_str) {\n                Ok(()) => {}\n                Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => {}\n                Err(e) => panic!(\"mkdirp: mkdir {} failed: {}\", new_path_str, e),\n            }\n        }\n        new_path_str\n    });\n}\n\npub fn generate_is_within_node_modules_fn(\n    root: &Path,\n    options: &FileOptions,\n) -> impl Fn(&str) -> bool {","sourceCodeStart":1342,"sourceCodeEnd":1378,"githubUrl":"https://github.com/facebook/flow/blob/f88ac94bcf6992f5d5a158854d94613ebb92c6e6/rust_port/crates/flow_common/src/files.rs#L1342-L1378","documentation":"mkdirp creates a path one component at a time (unix branch, with explicit mode from _perm). AlreadyExists is tolerated, but any other error panics with the failing component. Real causes: EACCES/EROFS on a parent, ENOTDIR when a regular file occupies a component position, ENAMETOOLONG, or EDQUOT.","triggerScenarios":"Creating flow's cache/temp directory trees when an intermediate component is a regular file (path like <tmp>/file.json/sub); parent directory lacks write permission; read-only or quota-limited filesystem; extremely long paths.","commonSituations":"TMPDIR pointing at a full/locked-down location; a previous crash leaving a file where flow expects a directory tree; sandboxed environments denying mkdir; shared caches on network volumes.","solutions":["Remove or rename the file occupying the failing component path shown in the panic","Fix write permissions on the parent directory (chmod/chown)","Set TMPDIR to a clean, writable, local directory and retry","Shorten deep paths or enable long-path support on Windows"],"exampleFix":"# before\n# a stray FILE named 'flow' blocks <tmp>/flow/...\ntouch /tmp/flow && flow check   # panics: mkdirp: mkdir /tmp/flow/x failed: Not a directory\n\n# after\nrm /tmp/flow\nflow check","handlingStrategy":"validation","validationCode":"# verify every ancestor of flow's temp/cache path is a directory and writable\npath=\"$TMPDIR/flow\"; p=\"\"\nfor part in $(echo \"$path\" | tr '/' ' '); do\n  p=\"$p/$part\"\n  [ -e \"$p\" ] && [ ! -d \"$p\" ] && echo \"BLOCKED: $p is a file\"\ndone\ntest -w \"$(dirname \"$path\")\" || echo \"parent not writable\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Point TMPDIR at a clean local directory you own","Clean up stray files left in flow temp/cache locations after crashes","Ensure write permission on every existing component of the target path"],"tags":["filesystem","mkdir","permissions","tmpdir"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"f88ac94bcf6992f5d5a158854d94613ebb92c6e6","analyzedAt":"2026-08-20T10:41:37.992Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}