Skip to content

Commit 09a21d9

Browse files
Paul Cwolfsoftwaresystemsltd
andcommitted
v0.4.5: tolerate missing [nginx] section and fail gracefully on bad config
The `nginx` field in `Config` was required, so a wolfproxy.toml without an `[nginx]` section (as produced by wolfstack's restore button) caused `toml::from_str` to fail with "missing field nginx", which the `.expect` turned into a panic + SIGABRT + coredump in the journal. Other working installs have always had `[nginx]` written by an earlier path; this only surfaced once restore wrote a stripped-down config. - Add `#[serde(default)]` to the `nginx` field — `NginxConfigSettings` already has a `Default` impl returning `config_dir = "/etc/nginx"`. - Replace `.expect` with a graceful `eprintln!` + `exit(1)` so a bad config produces a readable journal line instead of a coredump. Co-Authored-By: CodeWolf <paul@wolf.uk.com> Co-Authored-By: Wolf Software Systems Ltd <paul@wolf.uk.com>
1 parent 23a849d commit 09a21d9

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "wolfproxy"
3-
version = "0.4.4"
3+
version = "0.4.5"
44
edition = "2021"
55
description = "A Rust-based nginx proxy replacement that reads nginx configuration files"
66
authors = ["Wolf Software Systems Ltd"]

src/main.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ fn load_ssl_keys(cert_path: &Path, key_path: &Path) -> anyhow::Result<CertifiedK
134134
#[derive(Debug, Clone, Deserialize)]
135135
struct Config {
136136
server: ServerConfig,
137+
#[serde(default)]
137138
nginx: NginxConfigSettings,
138139
#[serde(default)]
139140
monitoring: MonitoringConfig,
@@ -300,7 +301,14 @@ password = "admin"
300301
}
301302
};
302303

303-
let config: Config = toml::from_str(&config_str).expect("Failed to parse wolfproxy.toml");
304+
let config: Config = match toml::from_str(&config_str) {
305+
Ok(c) => c,
306+
Err(e) => {
307+
eprintln!("Failed to parse wolfproxy.toml: {e}");
308+
eprintln!("Hint: ensure the file contains at minimum a [server] section with `host = \"0.0.0.0\"`. The [nginx], [monitoring], and [firewall] sections are optional and will use defaults if omitted.");
309+
std::process::exit(1);
310+
}
311+
};
304312

305313
info!("Loading nginx configuration from {}", config.nginx.config_dir);
306314

0 commit comments

Comments
 (0)