Skip to content

Commit

Permalink
[NFY] Use snafu for CLI error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Oct 22, 2024
1 parent 6206afa commit 8487387
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#![doc = include_str!("../README.md")]

use snafu::prelude::*;

Check failure on line 6 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared crate or module `snafu`

error[E0433]: failed to resolve: use of undeclared crate or module `snafu` --> src/lib.rs:6:5 | 6 | use snafu::prelude::*; | ^^^^^ use of undeclared crate or module `snafu`

Check failure on line 6 in src/lib.rs

View workflow job for this annotation

GitHub Actions / test

failed to resolve: use of undeclared crate or module `snafu`

use regex::Regex;
use titlecase::titlecase as gruber_titlecase;
use unicode_titlecase::tr_az::StrTrAzCasing;
Expand All @@ -26,6 +28,25 @@ pub mod python;
#[cfg(feature = "wasm")]
pub mod wasm;

#[derive(Snafu)]

Check failure on line 31 in src/lib.rs

View workflow job for this annotation

GitHub Actions / test

cannot find derive macro `Snafu` in this scope
pub enum Error {
#[snafu(display("std::io::Error {}", source))]

Check failure on line 33 in src/lib.rs

View workflow job for this annotation

GitHub Actions / test

cannot find attribute `snafu` in this scope
XXError {
source: std::io::Error,
},
UnresolvedError {},
}

// Clap CLI errors are reported using the Debug trait, but Snafu sets up the Display tait.
// So we deligate. c.f. https://github.com/shepmaster/snafu/issues/110
impl std::fmt::Debug for Error {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
std::fmt::Display::fmt(self, fmt)

Check failure on line 44 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

`Error` doesn't implement `std::fmt::Display`

error[E0277]: `Error` doesn't implement `std::fmt::Display` --> src/lib.rs:44:32 | 44 | std::fmt::Display::fmt(self, fmt) | ---------------------- ^^^^ `Error` cannot be formatted with the default formatter | | | required by a bound introduced by this call | = help: the trait `std::fmt::Display` is not implemented for `Error` = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead

Check failure on line 44 in src/lib.rs

View workflow job for this annotation

GitHub Actions / test

`Error` doesn't implement `std::fmt::Display`
}
}

pub type Result<T, E = Error> = std::result::Result<T, E>;

Check failure on line 48 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

the name `Result` is defined multiple times

error[E0255]: the name `Result` is defined multiple times --> src/lib.rs:48:1 | 17 | pub use types::{Case, Locale, Result, StyleGuide}; | ------ previous import of the type `Result` here ... 48 | pub type Result<T, E = Error> = std::result::Result<T, E>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Result` redefined here | = note: `Result` must be defined only once in the type namespace of this module help: you can use `as` to change the binding name of the import | 17 | pub use types::{Case, Locale, Result as OtherResult, StyleGuide}; | ++++++++++++++

Check failure on line 48 in src/lib.rs

View workflow job for this annotation

GitHub Actions / test

the name `Result` is defined multiple times

/// Convert a string to a specific case following typesetting conventions for a target locale
pub fn to_case(
chunk: impl Into<Chunk>,
Expand Down

0 comments on commit 8487387

Please sign in to comment.