the-benchmarker/web-frameworks · error
Failed to get current directory
Error message
Failed to get current directory
What it means
reinhardt-web's get_settings() reads REINHARDT_ENV and then calls std::env::current_dir() to locate the project's settings directory. If the operating system cannot determine the current working directory (process cwd deleted, or unavailable), the expect() panics with "Failed to get current directory".
Solutions
- Ensure the process is started with a valid, existing working directory (check container Workdir, service WorkingDirectory, test runner cwd)
- Do not delete or unmount the directory the process was started from while it is running
- If you control the code, replace expect with graceful handling: fall back to a configured base dir or a settings path from an env var instead of relying on cwd
- Pass the project root explicitly (e.g. REINHARDT_BASE_DIR env var) so settings lookup is independent of cwd
Example fix
// before
let base_dir = env::current_dir().expect("Failed to get current directory");
// after
let base_dir = env::var("REINHARDT_BASE_DIR")
.map(PathBuf::from)
.or_else(|_| env::current_dir())
.expect("Failed to determine project base directory"); Defensive patterns
Strategy: try-catch
Validate before calling
// before calling get_settings(), verify the process cwd is usable
use std::env;
match env::current_dir() {
Ok(dir) if dir.exists() => println!("cwd ok: {:?}", dir),
_ => {
eprintln!("current working directory is invalid; start the process from an existing directory");
std::process::exit(1);
}
} Type guard
fn cwd_is_valid() -> bool {
std::env::current_dir().map(|d| d.exists()).unwrap_or(false)
} Try / catch
// get_settings panics rather than returning Result, so catch the unwind if you embed it
let settings = std::panic::catch_unwind(reinhardt_web::config::settings::get_settings)
.unwrap_or_else(|_| {
eprintln!("settings unavailable: check working directory and REINHARDT_ENV");
std::process::exit(1);
}); Prevention
- Start services and tests from a directory that outlives the process; avoid deleting the cwd while running
- Set container/service workdir explicitly to an existing path
- Prefer passing the project root via an env var instead of relying on cwd
- Add a startup health check that fails fast with a clear message when cwd is unusable
When it happens
Trigger: Calling get_settings() (e.g. from test_get_settings) while the process's working directory has been unlinked, or in a sandbox/runtime where cwd is not accessible; current_dir() returns Err and expect unwraps it into a panic.
Common situations: Tests run in a temp directory that a cleanup step deletes mid-run; a long-lived process whose cwd was removed by another job; container runtimes started with an invalid Workdir; cwd on a mounted volume that was unmounted.
Related errors
AI-assisted analysis of the-benchmarker/web-frameworks@3795a31d72 (2026-09-15).
Data as JSON: /api/errors/434b17049110bb9b.
Report an issue: GitHub.
Appendix: source
Thrown at rust/reinhardt-web/src/config/settings.rs:77
///
/// ```no_run
/// use server::config::settings::get_settings;
///
/// let settings = get_settings();
/// ```
///
/// # Panics
///
/// Panics if:
/// - Settings files cannot be read
/// - Settings cannot be deserialized
/// - Required settings are missing
pub fn get_settings() -> ProjectSettings {
let profile_str = env::var("REINHARDT_ENV").unwrap_or_else(|_| "local".to_string());
let profile = Profile::parse(&profile_str);
// Get the project root directory (parent of src/)
let base_dir = env::current_dir().expect("Failed to get current directory");
let settings_dir = base_dir.join("settings");
// Build settings by merging sources in priority order.
// `build_composed::<T>()` uses `MergeStrategy::Deep` by default, so a
// single key in `production.toml` overrides only that key — sibling
// entries inside the same nested table inherit from `base.toml`.
SettingsBuilder::new()
.profile(profile)
// Lowest priority: Default values
.add_source(DefaultSource::new())
// Medium priority: Base TOML file
.add_source(TomlFileSource::new(settings_dir.join("base.toml")))
// Profile priority: Environment-specific TOML file
.add_source(TomlFileSource::new(
settings_dir.join(format!("{}.toml", profile_str)),
))
// Highest priority: explicit process environment overrides
.add_source(HighPriorityEnvSource::new().with_prefix("REINHARDT_"))View on GitHub (pinned to 3795a31d72)