mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 12:22:34 +00:00
refactor to use exception helper factories
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user