{"record":{"id":"61c0e6ef24cb6b2a","repo":"vectordotdev/vector","slug":"failed-to-create-output-dir-s","errorCode":null,"errorMessage":"Failed to create output dir(s): {:?}","messagePattern":"Failed to create output dir\\(s\\): (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/convert_config.rs","lineNumber":69,"sourceCode":"\n    Ok(())\n}\n\npub(crate) fn cmd(opts: &Opts) -> exitcode::ExitCode {\n    if let Err(e) = check_paths(opts) {\n        #[allow(clippy::print_stderr)]\n        {\n            eprintln!(\"{}\", e.red());\n        }\n        return exitcode::SOFTWARE;\n    }\n\n    if opts.input_path.is_file() && opts.output_path.extension().is_some() {\n        if let Some(base_dir) = opts.output_path.parent()\n            && !base_dir.exists()\n        {\n            fs::create_dir_all(base_dir).unwrap_or_else(|_| {\n                panic!(\"Failed to create output dir(s): {:?}\", &opts.output_path)\n            });\n        }\n\n        match convert_config(&opts.input_path, &opts.output_path, opts.output_format) {\n            Ok(_) => exitcode::OK,\n            Err(errors) => {\n                #[allow(clippy::print_stderr)]\n                {\n                    errors.iter().for_each(|e| eprintln!(\"{}\", e.red()));\n                }\n                exitcode::SOFTWARE\n            }\n        }\n    } else {\n        match walk_dir_and_convert(&opts.input_path, &opts.output_path, opts.output_format) {\n            Ok(()) => {\n                #[allow(clippy::print_stdout)]\n                {","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/src/convert_config.rs#L51-L87","documentation":"cmd, when converting a single config file to an output path with an extension, ensures the output file's parent directory exists by calling fs::create_dir_all. If creating that directory chain fails, it panics with 'Failed to create output dir(s): <path>'.","triggerScenarios":"Running the converter with a single input file and an output path whose parent directory does not exist and cannot be created (permission denied on ancestor, ancestor is a file, disk full, invalid path characters).","commonSituations":"Writing output into a read-only directory, deep output paths where a path component is actually a regular file, or running the tool as a user without write access to the target directory.","solutions":["Pre-create the output parent directory manually (mkdir -p) and check permissions","Ensure no path component of the output is an existing regular file","Run the command as a user with write permission on the target location","Patch the tool to map the io::Error into an Err instead of panicking"],"exampleFix":"// before\nfs::create_dir_all(base_dir)\n    .unwrap_or_else(|_| panic!(\"Failed to create output dir(s): {:?}\", &opts.output_path));\n// after\nfs::create_dir_all(base_dir)\n    .map_err(|e| format!(\"Failed to create output dir(s) {:?}: {}\", base_dir, e))?;","handlingStrategy":"validation","validationCode":"if let Some(parent) = opts.output_path.parent() {\n    assert!(!parent.exists() || parent.is_dir(), \"parent must be creatable dir\");\n    std::fs::create_dir_all(parent).expect(\"pre-create output dirs\");\n}","typeGuard":"fn can_write_dir(p: &std::path::Path) -> bool { p.is_dir() && fs::metadata(p).map(|m| !m.permissions().readonly()).unwrap_or(false) }","tryCatchPattern":null,"preventionTips":["Pre-create output directories with mkdir -p before running the tool","Check write permissions on the output tree for the running user","Ensure no output path component collides with an existing regular file"],"tags":["rust","panic","filesystem","mkdir"],"backgroundTag":"file-write-failed","analyzedSha":"bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013","analyzedAt":"2026-09-16T02:53:35.741Z","contentChangedAt":"2026-09-16T02:53:35.741Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}