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

@@ -58,22 +58,22 @@ impl Writer for QRCodeWriter {
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::QR_CODE {
return Err(Exceptions::IllegalArgumentException(Some(format!(
return Err(Exceptions::illegalArgument(format!(
"can only encode QR_CODE, but got {format:?}"
))));
)));
// throw new IllegalArgumentException("Can only encode QR_CODE, but got " + format);
}
if width < 0 || height < 0 {
return Err(Exceptions::IllegalArgumentException(Some(format!(
return Err(Exceptions::illegalArgument(format!(
"requested dimensions are too small: {width}x{height}"
))));
)));
}
let errorCorrectionLevel = if let Some(EncodeHintValue::ErrorCorrection(ec_level)) =
@@ -86,9 +86,9 @@ impl Writer for QRCodeWriter {
let quietZone =
if let Some(EncodeHintValue::Margin(margin)) = hints.get(&EncodeHintType::MARGIN) {
margin.parse::<i32>().map_err(|e| {
Exceptions::ParseException(Some(format!("could not parse {margin}: {e}")))
})?
margin
.parse::<i32>()
.map_err(|e| Exceptions::parse(format!("could not parse {margin}: {e}")))?
} else {
QUIET_ZONE_SIZE
};
@@ -110,14 +110,10 @@ impl QRCodeWriter {
) -> Result<BitMatrix, Exceptions> {
let input = code.getMatrix();
if input.is_none() {
return Err(Exceptions::IllegalStateException(Some(
"matrix is empty".to_owned(),
)));
return Err(Exceptions::illegalState("matrix is empty".to_owned()));
}
let input = input
.as_ref()
.ok_or(Exceptions::IllegalStateException(None))?;
let input = input.as_ref().ok_or(Exceptions::illegalStateEmpty())?;
let inputWidth = input.getWidth() as i32;
let inputHeight = input.getHeight() as i32;