Use thiserror for error handling with less boilerplate

This commit is contained in:
Steve Cook
2023-02-20 09:41:28 -05:00
parent 01e4f4a126
commit f8b29f37db
135 changed files with 868 additions and 905 deletions

View File

@@ -61,17 +61,17 @@ impl Writer for DataMatrixWriter {
hints: &crate::EncodingHintDictionary,
) -> Result<crate::common::BitMatrix> {
if contents.is_empty() {
return Err(Exceptions::illegalArgumentWith("Found empty contents"));
return Err(Exceptions::illegal_argument_with("Found empty contents"));
}
if format != &BarcodeFormat::DATA_MATRIX {
return Err(Exceptions::illegalArgumentWith(format!(
return Err(Exceptions::illegal_argument_with(format!(
"Can only encode DATA_MATRIX, but got {format:?}"
)));
}
if width < 0 || height < 0 {
return Err(Exceptions::illegalArgumentWith(format!(
return Err(Exceptions::illegal_argument_with(format!(
"Requested dimensions can't be negative: {width}x{height}"
)));
}
@@ -122,7 +122,7 @@ impl Writer for DataMatrixWriter {
if hasEncodingHint {
let Some(EncodeHintValue::CharacterSet(char_set_name)) =
hints.get(&EncodeHintType::CHARACTER_SET) else {
return Err(Exceptions::illegalArgumentWith("charset does not exist"))
return Err(Exceptions::illegal_argument_with("charset does not exist"))
};
charset = encoding::label::encoding_from_whatwg_label(char_set_name);
// charset = Charset.forName(hints.get(EncodeHintType.CHARACTER_SET).toString());
@@ -156,7 +156,7 @@ impl Writer for DataMatrixWriter {
let symbol_lookup = SymbolInfoLookup::new();
let Some(symbolInfo) = symbol_lookup.lookup_with_codewords_shape_size_fail(encoded.chars().count() as u32, *shape, &minSize, &maxSize, true)? else {
return Err(Exceptions::notFoundWith("symbol info is bad"))
return Err(Exceptions::not_found_with("symbol info is bad"))
};
//2. step: ECC generation