valeriansaliou/sonic · critical · panic

Cannot find config file at {custom_path:?}

Error message

Cannot find config file at {custom_path:?}

What it means

read_config panics when a custom config path was supplied (e.g. via -c/--config) but no file exists at that path. Sonic aborts immediately rather than silently falling back to defaults, because the user explicitly requested that file.

Source

Thrown at server/src/config.rs:124

        back_compat::migrate_channel_search(&mut server_config.channel, &mut core_config);

        // Validate configuration.
        core_config.validate();

        Config {
            channel: server_config.channel,
            server: server_config.server,
            sonic: Arc::new(core_config),
        }
    }
}

pub fn read_config(custom_path: Option<&str>) -> Config {
    if let Some(custom_path) = custom_path {
        // Abort if the user specified a config path that does not exist.
        if !std::path::Path::new(custom_path).exists() {
            panic!("Cannot find config file at {custom_path:?}");
        }

        let path = std::path::absolute(custom_path).unwrap();
        tracing::debug!("reading config file: {path:?}");

        Config::parse(config::File::from(path).format(config::FileFormat::Toml))
    } else {
        for path in DEFAULT_CONFIG_FILE_PATHS {
            let path = std::path::absolute(path).unwrap();
            tracing::debug!("looking for config file at {path:?}");

            if path.exists() {
                tracing::debug!("reading config file: {path:?}");

                return Config::parse(config::File::from(path).format(config::FileFormat::Toml));
            }
        }

View on GitHub (pinned to e6a72da6a5)

Solutions

  1. Verify the path exists: ls <path> — fix typos or the working directory
  2. Pass an absolute path to the config flag
  3. In containers, ensure the config file is mounted into the image/pod
  4. Omit the custom path to use the default config lookup

Example fix

// shell
// before
./sonic -c ./confg.toml  # typo
// after
./sonic -c /etc/sonic/config.toml
Defensive patterns

Strategy: validation

Validate before calling

let path = std::path::Path::new(custom_path);
if !path.exists() {
    return Err(format!("config file not found: {}", custom_path));
}

Prevention

When it happens

Trigger: Calling read_config(Some("path/to/config.toml")) where std::path::Path::new(custom_path).exists() is false — typically from main after CLI parsing.

Common situations: Typo in the --config flag; relative path from a different working directory; config file deleted or not mounted in a container; wrong file extension/location after a packaging change.

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 valeriansaliou/sonic@e6a72da6a5 (2026-09-01). Data as JSON: /api/errors/08562ae70f88cb27. Report an issue: GitHub.