nautechsystems/nautilus_trader · error

Failed to get current directory

Error message

Failed to get current directory

What it means

run_tardis_machine_replay_from_config resolves the output data path from config, then the NAUTILUS_PATH env var, and finally falls back to the process current directory. If none are set and std::env::current_dir() fails (working directory deleted or unreadable), the expect panics with 'Failed to get current directory'.

Source

Thrown at crates/adapters/tardis/src/replay.rs:104

    log::debug!("Config filepath: {}", config_filepath.display());

    // Load and parse the replay configuration
    let config_data = fs::read_to_string(config_filepath)
        .with_context(|| format!("Failed to read config file: {}", config_filepath.display()))?;
    let config: TardisReplayConfig = serde_json::from_str(&config_data)
        .context("failed to parse config JSON into TardisReplayConfig")?;

    let path = config
        .output_path
        .as_deref()
        .map(Path::new)
        .map(Path::to_path_buf)
        .or_else(|| {
            std::env::var("NAUTILUS_PATH")
                .ok()
                .map(|env_path| PathBuf::from(env_path).join("catalog").join("data"))
        })
        .unwrap_or_else(|| std::env::current_dir().expect("Failed to get current directory"));

    log::debug!("Output path: {}", path.display());

    let normalize_symbols = config.normalize_symbols.unwrap_or(true);
    log::debug!("normalize_symbols={normalize_symbols}");

    let book_snapshot_output = config
        .book_snapshot_output
        .clone()
        .unwrap_or(BookSnapshotOutput::Deltas);
    log::debug!("book_snapshot_output={book_snapshot_output:?}");

    let extract_bbo_as_quotes = config.extract_bbo_as_quotes.unwrap_or(false);
    log::debug!("extract_bbo_as_quotes={extract_bbo_as_quotes}");

    let compression = config
        .compression
        .clone()

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Set NAUTILUS_PATH to a writable root directory so the fallback to cwd is never used.
  2. Pass an explicit output path in the TardisMachineReplayConfig.
  3. Recreate the removed working directory or `cd` to an existing, readable directory before launching.

Example fix

// before
subprocess: (cd /tmp/gone-dir && nautilus tardis replay ...) # panics

// after
$ export NAUTILUS_PATH=/data/nautilus
$ cd /data/nautilus && nautilus tardis replay ...
Defensive patterns

Strategy: validation

Validate before calling

# before launching the replay
import os
if not os.environ.get("NAUTILUS_PATH") and config.catalog_path is None:
    os.chdir("/data/nautilus")  # ensure a valid, existing cwd
assert os.path.isdir(os.getcwd()), "working directory missing"

Type guard

fn cwd_is_readable() -> bool {
    std::env::current_dir().is_ok()
}

Try / catch

try:
    run_tardis_machine_replay(config)
except BaseException as e:
    print(f"replay failed (check cwd / NAUTILUS_PATH): {e}")

Prevention

When it happens

Trigger: Running py_run_tardis_machine_replay with neither an output path in the config nor NAUTILUS_PATH set, while the process cwd no longer exists (deleted directory) or lacks read permission.

Common situations: Launching a replay from a shell whose cwd was removed by another process or a tmpfs cleanup; running inside a container started with a stale workdir; NFS/permission problems.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/24d193d739583798. Report an issue: GitHub.