getzola/zola · error

{} not found in current directory or ancestors, current_dir

Error message

{} not found in current directory or ancestors, current_dir is {}

What it means

get_config_file_path resolves the config file: when the user passed an explicit --config path, Zola walks up from the current directory through ancestors looking for a directory containing that file. If none is found, it prints this error via unravel_errors and exits the process with code 1.

Source

Thrown at src/main.rs:26

use utils::net::{get_available_port, port_is_available};

use clap::{CommandFactory, Parser};
use time::UtcOffset;

mod cli;
mod cmd;
mod fs_utils;
mod messages;
mod prompt;

fn get_config_file_path(dir: &Path, config_path: Option<&Path>) -> (PathBuf, PathBuf) {
    let (root_dir, config_path) = match config_path {
        Some(path) => {
            // User specified a config file, use it directly
            let root = dir.ancestors().find(|a| a.join(path).exists()).unwrap_or_else(|| {
                messages::unravel_errors(
                    "",
                    &anyhow!(
                        "{} not found in current directory or ancestors, current_dir is {}",
                        path.display(),
                        dir.display()
                    ),
                );
                std::process::exit(1);
            });
            (root, path.to_path_buf())
        }
        None => {
            // Try zola.toml first, then fall back to config.toml
            let zola_config = Path::new("zola.toml");
            let legacy_config = Path::new("config.toml");

            if let Some(root) = dir.ancestors().find(|a| a.join(zola_config).exists()) {
                (root, zola_config.to_path_buf())
            } else if let Some(root) = dir.ancestors().find(|a| a.join(legacy_config).exists()) {
                (root, legacy_config.to_path_buf())

View on GitHub (pinned to 61d3082821)

Solutions

  1. cd to the directory that actually contains the named config file before running zola
  2. Fix the --config argument spelling/path, or pass a path relative to the current directory that resolves
  3. Verify the file exists: ls path/to/your-config.toml
  4. If you meant the default config, drop the --config flag so Zola looks for zola.toml/config.toml

Example fix

// before
zola build --config production.toml   # file only in ./config/
// after
zola build --config config/production.toml
Defensive patterns

Strategy: validation

Validate before calling

// shell: fail fast with a clear message before invoking zola
CONFIG="${ZOLA_CONFIG:-config/production.toml}"
[ -f "$CONFIG" ] || { echo "config not found: $CONFIG"; exit 1; }
zola build --config "$CONFIG"

Try / catch

// shell
if ! zola build --config "$CFG"; then
  echo "Check --config path; it must exist in cwd or an ancestor"
fi

Prevention

When it happens

Trigger: Running any zola command with an explicit --config CONFIG (e.g. --config config.production.toml) where neither the current directory nor any ancestor contains that file — wrong working directory, misspelled config name, or file outside the ancestor chain.

Common situations: CI jobs running zola from the repo root while the custom config lives in a subfolder; renaming the config file but forgetting to update the --config flag; passing a path that exists elsewhere but not in the ancestor chain of the cwd.

Understand the failure class

Background: "Config file not found": what it means and how to fix it in docker-sync, Maven, Vagrant, Turborepo and other tools — this error's family across 60 libraries.

Related errors


AI-assisted analysis of getzola/zola@61d3082821 (2026-09-03). Data as JSON: /api/errors/3a181bbcff3be5ba. Report an issue: GitHub.