linera-io/linera-protocol · error

Unable to read the configuration file

Error message

Unable to read the configuration file

What it means

linera-exporter's RunOptions::run (linera-exporter/src/main.rs:236) reads the TOML config file at --config with fs_err::read_to_string and panics if the read fails. Although run returns anyhow::Result, this particular failure is an expect, so a missing or unreadable config file crashes the process with a panic instead of a clean error. Causes: nonexistent path, wrong path, permission denied, or the path pointing at a directory.

Source

Thrown at linera-exporter/src/main.rs:238

    }
}

impl RunOptions {
    #[cfg(with_metrics)]
    fn enable_memory_profiling(&self) -> bool {
        #[cfg(feature = "jemalloc")]
        {
            self.enable_memory_profiling
        }
        #[cfg(not(feature = "jemalloc"))]
        {
            false
        }
    }

    fn run(&self) -> anyhow::Result<()> {
        let config_string = fs_err::read_to_string(&self.config_path)
            .expect("Unable to read the configuration file");
        let mut config: BlockExporterConfig =
            toml::from_str(&config_string).expect("Invalid configuration file format");

        let node_options = NodeOptions {
            send_timeout: self.send_timeout,
            recv_timeout: self.recv_timeout,
            retry_delay: self.retry_delay,
            max_retries: self.max_retries,
            max_backoff: self.max_backoff,
        };

        if let Some(port) = self.metrics_port {
            if IS_WITH_METRICS {
                tracing::info!("overriding metrics port to {}", port);
                config.metrics_port = port;
            } else {
                tracing::warn!(
                    "Metrics are not enabled in this build, ignoring metrics port configuration."

View on GitHub (pinned to 6c226ddcb3)

Solutions

  1. Verify the path exists and is readable before launch: `test -r /path/to/exporter.toml && echo ok`.
  2. Use an absolute path for --config in service definitions, containers, and scripts.
  3. Check ownership/permissions (chown/chmod) if the exporter runs as a non-root user.
  4. Confirm the file is a regular file, not a directory or a broken symlink.

Example fix

# before
linera-exporter run --config exporter.toml   # panics if missing from this cwd

# after
CONFIG=/etc/linera/exporter.toml
test -r "$CONFIG" || { echo "config not readable: $CONFIG" >&2; exit 1; }
linera-exporter run --config "$CONFIG"
Defensive patterns

Strategy: validation

Validate before calling

use std::path::Path;

let config_path = Path::new(&options.config_path);
let meta = std::fs::metadata(config_path)
    .map_err(|e| anyhow::anyhow!("cannot access config {}: {e}", config_path.display()))?;
if !meta.is_file() {
    anyhow::bail!("config path is not a file: {}", config_path.display());
}

Try / catch

// The panic happens in a third-party binary; guard at the orchestration layer:
use std::process::Command;
let status = Command::new("linera-exporter")
    .args(["run", "--config", config_path])
    .status()?;
if !status.success() {
    // read the panic message from stderr; typically 'Unable to read the configuration file'
}

Prevention

When it happens

Trigger: Starting the block exporter with `linera-exporter run --config <path>` where <path> does not exist, is not readable by the current user, is a directory, or a relative path resolved from a different working directory.

Common situations: Typo'd or stale config path in a systemd unit or container entrypoint; config file not mounted into the container; running from a different cwd so the relative path misses; file owned by root while the exporter runs as another user.

Related errors


AI-assisted analysis of linera-io/linera-protocol@6c226ddcb3 (2026-08-22). Data as JSON: /api/errors/51eac8468d9c640f. Report an issue: GitHub.