Skip to content

Commit

Permalink
fix(config): print file path on file read error (#354)
Browse files Browse the repository at this point in the history
* Display file path that failed to be read

* Fix some docs in the config template
  • Loading branch information
Alex6323 authored Jun 28, 2022
1 parent dbef5f1 commit 09849bc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions bin/inx-chronicle/config.template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ database_name = "chronicle"
### API listening port.
port = 8042

### CORS
### CORS.
allow_origins = "0.0.0.0"

### JsonWebToken (JWT) credentials.
Expand Down Expand Up @@ -44,5 +44,5 @@ sync_start_milestone = 1
### Bind address of the metrics server.
address = "0.0.0.0"

### Port
### Bind port of the metrics server.
port = 9100
6 changes: 3 additions & 3 deletions bin/inx-chronicle/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub enum ConfigError {
#[cfg(feature = "api")]
#[error(transparent)]
Api(#[from] crate::api::ConfigError),
#[error("failed to read file: {0}")]
FileRead(std::io::Error),
#[error("failed to read config at '{0}': {1}")]
FileRead(String, std::io::Error),
#[error("toml deserialization failed: {0}")]
TomlDeserialization(toml::de::Error),
}
Expand All @@ -34,7 +34,7 @@ pub struct ChronicleConfig {
impl ChronicleConfig {
pub fn from_file(path: impl AsRef<Path>) -> Result<Self, ConfigError> {
fs::read_to_string(&path)
.map_err(ConfigError::FileRead)
.map_err(|e| ConfigError::FileRead(path.as_ref().display().to_string(), e))
.and_then(|contents| toml::from_str::<Self>(&contents).map_err(ConfigError::TomlDeserialization))
}

Expand Down

0 comments on commit 09849bc

Please sign in to comment.