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

@@ -222,14 +222,14 @@ pub fn encodeHighLevelWithDimensionForceC40WithSymbolInfoLookup(
if forceC40 {
c40Encoder.encodeMaximalC40(&mut context)?;
encodingMode = context.getNewEncoding().ok_or(Exceptions::illegalState)?;
encodingMode = context.getNewEncoding().ok_or(Exceptions::ILLEGAL_STATE)?;
context.resetEncoderSignal();
}
while context.hasMoreCharacters() {
encoders[encodingMode].encode(&mut context)?;
if context.getNewEncoding().is_some() {
encodingMode = context.getNewEncoding().ok_or(Exceptions::illegalState)?;
encodingMode = context.getNewEncoding().ok_or(Exceptions::ILLEGAL_STATE)?;
context.resetEncoderSignal();
}
}
@@ -237,7 +237,7 @@ pub fn encodeHighLevelWithDimensionForceC40WithSymbolInfoLookup(
context.updateSymbolInfo();
let capacity = context
.getSymbolInfo()
.ok_or(Exceptions::illegalState)?
.ok_or(Exceptions::ILLEGAL_STATE)?
.getDataCapacity();
if len < capacity as usize
&& encodingMode != ASCII_ENCODATION
@@ -608,7 +608,7 @@ pub fn determineConsecutiveDigitCount(msg: &str, startpos: u32) -> u32 {
pub fn illegalCharacter(c: char) -> Result<()> {
// let hex = Integer.toHexString(c);
// hex = "0000".substring(0, 4 - hex.length()) + hex;
Err(Exceptions::illegalArgumentWith(format!(
Err(Exceptions::illegal_argument_with(format!(
"Illegal character: {c} (0x{c})"
)))
}