Skip to content

Commit

Permalink
refactor: Update error messages for more information on how to debug …
Browse files Browse the repository at this point in the history
…issues
  • Loading branch information
inflation committed Sep 6, 2024
1 parent b4b7098 commit b237d65
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
38 changes: 38 additions & 0 deletions jpegxl-rs/src/decode/event.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use std::ffi::c_int;

/// Target of the color profile.
pub use jpegxl_sys::decode::JxlColorProfileTarget as ColorProfileTarget;

use super::{ColorEncodingConfig, Config};

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Event {
BasicInfo,
ColorEncoding(ColorEncodingConfig),
}

impl From<Event> for c_int {
fn from(value: Event) -> Self {
match value {
Event::BasicInfo => 0x40,
Event::ColorEncoding { .. } => 0x100,

Check warning on line 18 in jpegxl-rs/src/decode/event.rs

View check run for this annotation

Codecov / codecov/patch

jpegxl-rs/src/decode/event.rs#L18

Added line #L18 was not covered by tests
}
}
}

pub(crate) fn parse_events<I>(iter: I) -> (c_int, Config)
where
I: IntoIterator<Item = Event>,
{
iter.into_iter()
.fold((0, Config::default()), |(flag, config), x| {
let flag = flag | c_int::from(x);
let config = match x {
Event::ColorEncoding(val) => Config {
color_profile: Some(val),
},

Check warning on line 33 in jpegxl-rs/src/decode/event.rs

View check run for this annotation

Codecov / codecov/patch

jpegxl-rs/src/decode/event.rs#L31-L33

Added lines #L31 - L33 were not covered by tests
_ => config,

Check failure on line 34 in jpegxl-rs/src/decode/event.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] jpegxl-rs/src/decode/event.rs#L34

error: wildcard matches only a single variant and will also match any future added variants --> jpegxl-rs/src/decode/event.rs:34:17 | 34 | _ => config, | ^ help: try: `Event::BasicInfo` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_wildcard_for_single_variants = note: `-D clippy::match-wildcard-for-single-variants` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::match_wildcard_for_single_variants)]`
Raw output
jpegxl-rs/src/decode/event.rs:34:17:e:error: wildcard matches only a single variant and will also match any future added variants
  --> jpegxl-rs/src/decode/event.rs:34:17
   |
34 |                 _ => config,
   |                 ^ help: try: `Event::BasicInfo`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_wildcard_for_single_variants
   = note: `-D clippy::match-wildcard-for-single-variants` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(clippy::match_wildcard_for_single_variants)]`


__END__
};
(flag, config)
})
}
15 changes: 12 additions & 3 deletions jpegxl-rs/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@ pub enum DecodeError {
#[error("Cannot create a decoder")]
CannotCreateDecoder,
/// Unknown Error
#[error("Generic Error")]
#[error(
"Generic Error. Please build `libjxl` from source (using `vendored` feature)
in debug mode to get more information. Check `stderr` for any internal error messages."
)]
GenericError,
/// Invalid input
#[error("The input does not contain a valid codestream or container")]
InvalidInput,
/// Unsupported Pixel bit width
#[error("Unsupported Pixel bit width: {0}")]
UnsupportedBitWidth(u32),
#[error("Invalid usage of the library, please file an issus: {0}")]
InvalidUsage(&'static str),
/// Unknown status
#[error("Unknown status: `{0:?}`")]
UnknownStatus(JxlDecoderStatus),
Expand All @@ -49,7 +54,10 @@ pub enum EncodeError {
#[error("Cannot create an encoder")]
CannotCreateEncoder,
/// Generic Error
#[error("Generic Error")]
#[error(
"Generic Error. Please build `libjxl` from source (using `vendored` feature)
in debug mode to get more information. Check `stderr` for any internal error messages."
)]
GenericError,
/// Not Supported
#[error("Encoder does not support it (yet)")]
Expand All @@ -66,7 +74,8 @@ pub enum EncodeError {
/// Input is invalid (e.g. corrupt JPEG file or ICC profile)
#[error("Input is invalid")]
BadInput,
/// The encoder API is used in an incorrect way. In this case, a debug build of libjxl should output a specific error message
/// The encoder API is used in an incorrect way. In this case,
/// a debug build of libjxl should output a specific error message
#[error("The encoder API is used in an incorrect way")]
ApiUsage,
/// Unknown status
Expand Down

0 comments on commit b237d65

Please sign in to comment.