Skip to content

Commit

Permalink
refactor: extract ConfigParseError::IoError as an independent error type
Browse files Browse the repository at this point in the history
Signed-off-by: Phoeniix Zhao <[email protected]>
  • Loading branch information
Phoenix500526 committed Oct 11, 2023
1 parent 1a849d6 commit f3d4c5b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,15 @@ pub enum ConfigParseError {
/// Invalid values
#[error("Invalid Value: {0}")]
InvalidValue(String),
/// Invalid config file path
#[error("Couldn't read file {0}")]
IoError(String, #[source] std::io::Error),
}

/// Config File Error
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum ConfigFileError {
/// Invalid number when parsing `Duration`
#[error("Couldn't read config file {0}")]
FileError(String, #[source] std::io::Error),
}

/// parse members from string like "node1=addr1,addr2,node2=add3,addr4,addr5,node3=addr6"
Expand Down
4 changes: 2 additions & 2 deletions xline/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ use utils::{
RotationConfig, ServerTimeout, StorageConfig, TraceConfig, XlineServerConfig,
},
parse_batch_bytes, parse_duration, parse_log_level, parse_members, parse_rotation,
ConfigParseError,
ConfigFileError,
};
use xline::{server::XlineServer, storage::db::DB};

Expand Down Expand Up @@ -488,7 +488,7 @@ async fn main() -> Result<()> {
env::var("XLINE_SERVER_CONFIG").unwrap_or_else(|_| "/etc/xline_server.conf".to_owned());
let config_file = fs::read_to_string(&path)
.await
.map_err(|err| ConfigParseError::IoError(path, err))?;
.map_err(|err| ConfigFileError::FileError(path, err))?;
toml::from_str(&config_file)?
} else {
let server_args: ServerArgs = ServerArgs::parse();
Expand Down

0 comments on commit f3d4c5b

Please sign in to comment.