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

@@ -102,14 +102,14 @@ impl Version {
*/
pub fn getProvisionalVersionForDimension(dimension: u32) -> Result<&'static Version> {
if dimension % 4 != 1 {
return Err(Exceptions::formatWith("dimension incorrect"));
return Err(Exceptions::format_with("dimension incorrect"));
}
Self::getVersionForNumber((dimension - 17) / 4)
}
pub fn getVersionForNumber(versionNumber: u32) -> Result<&'static Version> {
if !(1..=40).contains(&versionNumber) {
return Err(Exceptions::illegalArgumentWith("version out of spec"));
return Err(Exceptions::illegal_argument_with("version out of spec"));
}
Ok(&VERSIONS[versionNumber as usize - 1])
}
@@ -137,7 +137,7 @@ impl Version {
return Self::getVersionForNumber(bestVersion);
}
// If we didn't find a close enough match, fail
Err(Exceptions::notFound)
Err(Exceptions::NOT_FOUND)
}
/**