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

@@ -218,7 +218,7 @@ fn addEdge(edges: &mut [Vec<Option<Rc<Edge>>>], edge: Rc<Edge>) -> Result<()> {
if edges[vertexIndex][edge.getEndMode()?.ordinal()].is_none()
|| edges[vertexIndex][edge.getEndMode()?.ordinal()]
.as_ref()
.ok_or(Exceptions::illegalState)?
.ok_or(Exceptions::ILLEGAL_STATE)?
.cachedTotalSize
> edge.cachedTotalSize
{
@@ -635,7 +635,7 @@ fn encodeMinimally(input: Rc<Input>) -> Result<RXingResult> {
}
if minimalJ < 0 {
return Err(Exceptions::illegalStateWith(format!(
return Err(Exceptions::illegal_state_with(format!(
"Internal error: failed to encode \"{input}\""
)));
}
@@ -669,7 +669,7 @@ impl Edge {
previous: Option<Rc<Edge>>,
) -> Result<Self> {
if fromPosition + characterLength > input.length() as u32 {
return Err(Exceptions::format);
return Err(Exceptions::FORMAT);
}
let mut size = if let Some(previous) = previous.clone() {
@@ -1276,7 +1276,7 @@ impl RXingResult {
let solution = if let Some(edge) = solution {
edge
} else {
return Err(Exceptions::illegalArgument);
return Err(Exceptions::ILLEGAL_ARGUMENT);
};
let input = solution.input.clone();
let mut size = 0;