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 <lx@deuxfleurs.fr>
This commit is contained in:
jo
2026-06-17 13:53:43 +00:00
committed by Alex
parent a379406522
commit 1d1456f1d6
2 changed files with 13 additions and 3 deletions
+7 -1
View File
@@ -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<Config, Error> {
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)?)
}