-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from robertknight/propagate-recognition-errors
Propagate errors running recognition model, instead of panicking
- Loading branch information
Showing
3 changed files
with
44 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use std::error::Error; | ||
use std::fmt; | ||
|
||
/// The error type returned when running a machine learning model fails. | ||
#[derive(Debug)] | ||
pub enum ModelRunError { | ||
/// Model execution failed. | ||
RunFailed(Box<dyn Error + Send + Sync>), | ||
|
||
/// The model output had a different data type or shape than expected. | ||
WrongOutput, | ||
} | ||
|
||
impl fmt::Display for ModelRunError { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { | ||
match self { | ||
ModelRunError::RunFailed(err) => write!(f, "model run failed: {}", err), | ||
ModelRunError::WrongOutput => { | ||
write!(f, "model output had unexpected type or shape") | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl Error for ModelRunError {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters