mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-27 21:02:35 +00:00
Use thiserror for error handling with less boilerplate
This commit is contained in:
@@ -59,18 +59,18 @@ impl Writer for QRCodeWriter {
|
||||
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::QR_CODE {
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
return Err(Exceptions::illegal_argument_with(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::illegalArgumentWith(format!(
|
||||
return Err(Exceptions::illegal_argument_with(format!(
|
||||
"requested dimensions are too small: {width}x{height}"
|
||||
)));
|
||||
}
|
||||
@@ -87,7 +87,7 @@ impl Writer for QRCodeWriter {
|
||||
if let Some(EncodeHintValue::Margin(margin)) = hints.get(&EncodeHintType::MARGIN) {
|
||||
margin
|
||||
.parse::<i32>()
|
||||
.map_err(|e| Exceptions::parseWith(format!("could not parse {margin}: {e}")))?
|
||||
.map_err(|e| Exceptions::parse_with(format!("could not parse {margin}: {e}")))?
|
||||
} else {
|
||||
QUIET_ZONE_SIZE
|
||||
};
|
||||
@@ -109,10 +109,10 @@ impl QRCodeWriter {
|
||||
) -> Result<BitMatrix> {
|
||||
let input = code.getMatrix();
|
||||
if input.is_none() {
|
||||
return Err(Exceptions::illegalStateWith("matrix is empty"));
|
||||
return Err(Exceptions::illegal_state_with("matrix is empty"));
|
||||
}
|
||||
|
||||
let input = input.as_ref().ok_or(Exceptions::illegalState)?;
|
||||
let input = input.as_ref().ok_or(Exceptions::ILLEGAL_STATE)?;
|
||||
|
||||
let inputWidth = input.getWidth() as i32;
|
||||
let inputHeight = input.getHeight() as i32;
|
||||
|
||||
Reference in New Issue
Block a user