refactor to use exception helper factories

This commit is contained in:
Vukašin Stepanović
2023-02-15 10:46:13 +00:00
parent 3e27279dc8
commit 722ce78fd0
132 changed files with 966 additions and 1132 deletions

View File

@@ -60,21 +60,21 @@ impl Writer for DataMatrixWriter {
hints: &crate::EncodingHintDictionary,
) -> Result<crate::common::BitMatrix, crate::Exceptions> {
if contents.is_empty() {
return Err(Exceptions::IllegalArgumentException(Some(
return Err(Exceptions::illegalArgument(
"Found empty contents".to_owned(),
)));
));
}
if format != &BarcodeFormat::DATA_MATRIX {
return Err(Exceptions::IllegalArgumentException(Some(format!(
return Err(Exceptions::illegalArgument(format!(
"Can only encode DATA_MATRIX, but got {format:?}"
))));
)));
}
if width < 0 || height < 0 {
return Err(Exceptions::IllegalArgumentException(Some(format!(
return Err(Exceptions::illegalArgument(format!(
"Requested dimensions can't be negative: {width}x{height}"
))));
)));
}
// Try to get force shape & min / max size
@@ -123,7 +123,7 @@ impl Writer for DataMatrixWriter {
if hasEncodingHint {
let Some(EncodeHintValue::CharacterSet(char_set_name)) =
hints.get(&EncodeHintType::CHARACTER_SET) else {
return Err(Exceptions::IllegalArgumentException(Some("charset does not exist".to_owned())))
return Err(Exceptions::illegalArgument("charset does not exist".to_owned()))
};
charset = encoding::label::encoding_from_whatwg_label(char_set_name);
// charset = Charset.forName(hints.get(EncodeHintType.CHARACTER_SET).toString());
@@ -157,7 +157,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::NotFoundException(Some("symbol info is bad".to_owned())))
return Err(Exceptions::notFound("symbol info is bad".to_owned()))
};
//2. step: ECC generation