From 1d1456f1d6cd73279bcaf213067da58fd8d8cbc6 Mon Sep 17 00:00:00 2001 From: jo Date: Wed, 17 Jun 2026 13:53:43 +0000 Subject: [PATCH] Add details to read file errors (#1475) If the files configured in `api_token_file` or `rpc_secret_file` are not found, garage exits with no details (at least not enough) of what went wrong: 2026-06-14T23:40:34.517429Z INFO garage::server: Loading configuration from tmp/config1.toml... Error: IO error: No such file or directory (os error 2) This add the kind of file and the file path being read, to the returned error message: 2026-06-14T23:41:41.136213Z INFO garage::server: Loading configuration from tmp/config1.toml... Error: Failed to read secret file /run/secrets/rpc_secret: No such file or directory (os error 2) Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/1475 Reviewed-by: Alex --- src/garage/secrets.rs | 8 ++++++-- src/util/config.rs | 8 +++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/garage/secrets.rs b/src/garage/secrets.rs index cb65bf84..66cc84dc 100644 --- a/src/garage/secrets.rs +++ b/src/garage/secrets.rs @@ -137,14 +137,18 @@ fn read_secret_file(file_path: &PathBuf, allow_world_readable: bool) -> Result somefile`. // also editors sometimes add a trailing newline diff --git a/src/util/config.rs b/src/util/config.rs index aafc21b5..0395549e 100644 --- a/src/util/config.rs +++ b/src/util/config.rs @@ -282,7 +282,13 @@ pub fn default_block_max_concurrent_writes_per_request() -> usize { } /// Read and parse configuration pub fn read_config(config_file: PathBuf) -> Result { - let config = std::fs::read_to_string(config_file)?; + let config = std::fs::read_to_string(&config_file).map_err(|e| { + format!( + "Failed to read config file {}: {}", + config_file.display(), + e + ) + })?; Ok(toml::from_str(&config)?) }