-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: replace anyhow #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 8 commits
9e3160b
7780614
a6c4080
5c32031
e519efa
e481e7e
346c275
cbb94fc
9d3f173
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| use std::fmt::{self, Debug}; | ||
| use std::fs; | ||
|
|
||
| use dnrs::{Config, RuntimeError, run, setup_logger}; | ||
| use dnrs::{Config, ConfigError, RuntimeError, run, setup_logger}; | ||
| use lum_config::{ConfigPathError, EnvironmentConfigParseError, FileConfigParseError}; | ||
| use lum_log::{info, log::SetLoggerError}; | ||
| use thiserror::Error; | ||
|
|
@@ -59,7 +59,7 @@ enum Error { | |
| Io(#[from] std::io::Error), | ||
|
|
||
| #[error("Config error: {0}")] | ||
| Config(#[from] anyhow::Error), | ||
| Config(#[from] ConfigError), | ||
|
|
||
| #[error("Unable to determine config directory")] | ||
| NoConfigDirectory, | ||
|
|
@@ -78,22 +78,22 @@ impl Debug for Error { | |
| } | ||
| } | ||
|
|
||
| fn read_config() -> Result<Config, Error> { | ||
| fn read_config() -> Result<Config, Box<Error>> { | ||
| let config_dir = dirs::config_dir() | ||
| .ok_or(Error::NoConfigDirectory)? | ||
| .ok_or(Box::new(Error::NoConfigDirectory))? | ||
| .join(APP_NAME); | ||
|
|
||
| if config_dir.exists() && !config_dir.is_dir() { | ||
| return Err(Error::ConfigIsNotDirectory); | ||
| return Err(Box::new(Error::ConfigIsNotDirectory)); | ||
| } | ||
|
|
||
| let config = if config_dir.exists() { | ||
| Config::load_from_directory(&config_dir)? | ||
| Config::load_from_directory(&config_dir).map_err(|e| Box::new(Error::from(e)))? | ||
|
||
| } else { | ||
| info!("Config directory does not exist, creating default structure..."); | ||
| fs::create_dir_all(&config_dir)?; | ||
| fs::create_dir_all(&config_dir).map_err(|e| Box::new(Error::from(e)))?; | ||
|
||
|
|
||
| Config::create_example_structure(&config_dir)?; | ||
| Config::create_example_structure(&config_dir).map_err(|e| Box::new(Error::from(e)))?; | ||
|
||
| info!( | ||
| "Created default config structure at: {}", | ||
| config_dir.display() | ||
|
|
@@ -108,11 +108,11 @@ fn read_config() -> Result<Config, Error> { | |
| } | ||
|
|
||
| #[tokio::main] | ||
| async fn main() -> Result<(), Error> { | ||
| setup_logger()?; | ||
| async fn main() -> Result<(), Box<Error>> { | ||
| setup_logger().map_err(|e| Box::new(Error::from(e)))?; | ||
|
||
|
|
||
| let config = read_config()?; | ||
| run(config).await?; | ||
| run(config).await.map_err(|e| Box::new(Error::from(e)))?; | ||
|
||
|
|
||
| Ok(()) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check if it makes sense to use individual Error enums for the different methods below instead of having them all return the same general ConfigError enum? Or does every method below actually need all of the enum values? Then using the same ConfigError enum for all of them makes sense. Otherwise, define specific error enums per method.