vectordotdev/vector · error
Failed to create output dir(s)
Error message
Failed to create output dir(s): {:?} What it means
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>'.
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
Example fix
// before
fs::create_dir_all(base_dir)
.unwrap_or_else(|_| panic!("Failed to create output dir(s): {:?}", &opts.output_path));
// after
fs::create_dir_all(base_dir)
.map_err(|e| format!("Failed to create output dir(s) {:?}: {}", base_dir, e))?; Defensive patterns
Strategy: validation
Validate before calling
if let Some(parent) = opts.output_path.parent() {
assert!(!parent.exists() || parent.is_dir(), "parent must be creatable dir");
std::fs::create_dir_all(parent).expect("pre-create output dirs");
} Type guard
fn can_write_dir(p: &std::path::Path) -> bool { p.is_dir() && fs::metadata(p).map(|m| !m.permissions().readonly()).unwrap_or(false) } Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- Failed to create output dir
- Failed to bind to listener socket at path
- Failed to get entry for dir
- Failed to get extension for
- Failed to get file_name for
AI-assisted analysis of vectordotdev/vector@bdb87aeaa4 (2026-09-16).
Data as JSON: /api/errors/61c0e6ef24cb6b2a.
Report an issue: GitHub.
Appendix: source
Thrown at src/convert_config.rs:69
Ok(())
}
pub(crate) fn cmd(opts: &Opts) -> exitcode::ExitCode {
if let Err(e) = check_paths(opts) {
#[allow(clippy::print_stderr)]
{
eprintln!("{}", e.red());
}
return exitcode::SOFTWARE;
}
if opts.input_path.is_file() && opts.output_path.extension().is_some() {
if let Some(base_dir) = opts.output_path.parent()
&& !base_dir.exists()
{
fs::create_dir_all(base_dir).unwrap_or_else(|_| {
panic!("Failed to create output dir(s): {:?}", &opts.output_path)
});
}
match convert_config(&opts.input_path, &opts.output_path, opts.output_format) {
Ok(_) => exitcode::OK,
Err(errors) => {
#[allow(clippy::print_stderr)]
{
errors.iter().for_each(|e| eprintln!("{}", e.red()));
}
exitcode::SOFTWARE
}
}
} else {
match walk_dir_and_convert(&opts.input_path, &opts.output_path, opts.output_format) {
Ok(()) => {
#[allow(clippy::print_stdout)]
{View on GitHub (pinned to bdb87aeaa4)