Skip to content
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

Implements proper user error handling #5

Merged
merged 6 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]

[target.x86_64-unknown-linux-musl]
rustflags = ["-C", "target-feature=+crt-static"]
145 changes: 131 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions hypnagogic_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ tracing-subscriber = "0.3"
user-error ="1.2"
walkdir = "2.3"
hypnagogic-core = { path = "../hypnagogic_core" }
owo-colors = { version = "4.0.0", features = ["supports-colors"] }

[dev-dependencies]
tempfile = "3.5"
Expand Down
14 changes: 14 additions & 0 deletions hypnagogic_cli/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use std::io;
use std::path::PathBuf;

use hypnagogic_core::config::error::ConfigError;
use hypnagogic_core::operations::error::ProcessorError;
use hypnagogic_core::operations::{InputError, OutputError};
use thiserror::Error;
use user_error::UFE;

Expand All @@ -24,6 +26,12 @@ pub enum Error {
template_string: String,
expected_path: PathBuf,
},
#[error("Image Parsing Failed")]
InputParsingFailed(#[from] InputError),
#[error("Processing Failed")]
ProcessorFailed(#[from] ProcessorError),
#[error("Output Failed")]
OutputWriteFailed(#[from] OutputError),
#[error("No template folder")]
NoTemplateFolder(PathBuf),
#[error("Generic IO Error")]
Expand Down Expand Up @@ -74,6 +82,9 @@ impl UFE for Error {
format!("Expected template folder at {folder:?}"),
])
}
Error::InputParsingFailed(image_error) => image_error.reasons(),
Error::ProcessorFailed(process_error) => process_error.reasons(),
Error::OutputWriteFailed(output_error) => output_error.reasons(),
Error::IO(err) => {
Some(vec![format!(
"Operation failed for reason of \"{:?}\"",
Expand Down Expand Up @@ -110,6 +121,9 @@ impl UFE for Error {
.to_string(),
)
}
Error::InputParsingFailed(image_error) => image_error.helptext(),
Error::ProcessorFailed(process_error) => process_error.helptext(),
Error::OutputWriteFailed(output_error) => output_error.helptext(),
Error::IO(_) => {
Some(
"Make sure the directories or files aren't in use, and you have permission to \
Expand Down
Loading
Loading