pub enum OCRError {
ImageLoad(ImageError),
Processing {
kind: ProcessingStage,
context: String,
source: Box<dyn Error + Sync + Send>,
},
Inference {
model_name: String,
context: String,
source: Box<dyn Error + Sync + Send>,
},
ModelInference {
model_name: String,
operation: String,
batch_index: usize,
input_shape: Vec<usize>,
context: String,
source: Box<dyn Error + Sync + Send>,
},
InvalidInput {
message: String,
},
ConfigError {
message: String,
},
BufferTooSmall {
expected: usize,
actual: usize,
},
Session(Error),
TensorOperation {
operation: String,
expected_shape: Vec<usize>,
actual_shape: Vec<usize>,
context: String,
source: Box<dyn Error + Sync + Send>,
},
Tensor(ShapeError),
Io(Error),
ModelLoad {
model_path: String,
reason: String,
suggestion: String,
source: Option<Box<dyn Error + Sync + Send>>,
},
}Expand description
Enum representing various errors that can occur in the OCR pipeline.
This enum defines all the possible error types that can occur during the OCR process, including image loading errors, processing errors, inference errors, and configuration errors.
Variants§
ImageLoad(ImageError)
Error occurred while loading an image.
Processing
Error occurred during processing.
Fields
kind: ProcessingStageThe stage of processing where the error occurred.
Inference
Error occurred during inference.
Fields
ModelInference
Error occurred during model inference with detailed context.
Fields
InvalidInput
Error indicating invalid input.
ConfigError
Error indicating a configuration problem.
BufferTooSmall
Error indicating a buffer is too small.
Session(Error)
Error from the ONNX Runtime session.
TensorOperation
Error from tensor operations with detailed context.
Fields
Tensor(ShapeError)
Error from basic tensor operations (fallback for ndarray errors).
Io(Error)
IO error.
ModelLoad
Error loading a model file, with context and suggestions.
Implementations§
Source§impl OCRError
Implementation of OCRError with utility functions for creating errors.
impl OCRError
Implementation of OCRError with utility functions for creating errors.
Sourcepub fn tensor_operation(
context: &str,
error: impl Error + Send + Sync + 'static,
) -> OCRError
pub fn tensor_operation( context: &str, error: impl Error + Send + Sync + 'static, ) -> OCRError
Creates an OCRError for tensor operations (simple variant).
This is an alias for tensor_operation_error with default shape information.
For detailed tensor shape errors, use tensor_operation_error directly.
§Arguments
context- Additional context about the error.error- The underlying error that caused this error.
§Returns
An OCRError instance.
Sourcepub fn post_processing(
context: &str,
error: impl Error + Send + Sync + 'static,
) -> OCRError
pub fn post_processing( context: &str, error: impl Error + Send + Sync + 'static, ) -> OCRError
Sourcepub fn image_processing(
context: &str,
error: impl Error + Send + Sync + 'static,
) -> OCRError
pub fn image_processing( context: &str, error: impl Error + Send + Sync + 'static, ) -> OCRError
Sourcepub fn image_processing_error(message: impl Into<String>) -> OCRError
pub fn image_processing_error(message: impl Into<String>) -> OCRError
Creates an OCRError for image processing operations with a simple message.
This is an alias for image_processing with a std::io::Error wrapper.
For errors with underlying causes, use image_processing directly.
§Arguments
message- The error message describing what went wrong.
§Returns
An OCRError instance.
Sourcepub fn batch_processing(
context: &str,
error: impl Error + Send + Sync + 'static,
) -> OCRError
pub fn batch_processing( context: &str, error: impl Error + Send + Sync + 'static, ) -> OCRError
Creates an OCRError for batch processing operations (simple variant).
This is an alias for batch_processing_error with default batch information.
For detailed batch processing errors, use batch_processing_error directly.
§Arguments
context- Additional context about the error.error- The underlying error that caused this error.
§Returns
An OCRError instance.
Sourcepub fn processing_error(
kind: ProcessingStage,
context: &str,
error: impl Error + Send + Sync + 'static,
) -> OCRError
pub fn processing_error( kind: ProcessingStage, context: &str, error: impl Error + Send + Sync + 'static, ) -> OCRError
Creates an OCRError for processing operations (simple variant).
This is an alias for processing_error_with_details with default operation and input info.
For detailed processing errors, use processing_error_with_details directly.
§Arguments
kind- The stage of processing where the error occurred.context- Additional context about the error.error- The underlying error that caused this error.
§Returns
An OCRError instance.
Sourcepub fn invalid_input(message: impl Into<String>) -> OCRError
pub fn invalid_input(message: impl Into<String>) -> OCRError
Sourcepub fn config_error(message: impl Into<String>) -> OCRError
pub fn config_error(message: impl Into<String>) -> OCRError
Sourcepub fn validation_error(
component: &str,
field: &str,
expected: &str,
actual: &str,
) -> OCRError
pub fn validation_error( component: &str, field: &str, expected: &str, actual: &str, ) -> OCRError
Sourcepub fn processing_error_with_details(
stage: ProcessingStage,
operation: &str,
input_info: &str,
error: impl Error + Send + Sync + 'static,
) -> OCRError
pub fn processing_error_with_details( stage: ProcessingStage, operation: &str, input_info: &str, error: impl Error + Send + Sync + 'static, ) -> OCRError
Creates an OCRError for processing operations with detailed context.
§Arguments
stage- The stage of processing where the error occurred.operation- The operation that failed.input_info- Information about the input.error- The underlying error that caused this error.
§Returns
An OCRError instance.
Sourcepub fn model_inference_error(
model_name: &str,
operation: &str,
batch_index: usize,
input_shape: &[usize],
context: &str,
error: impl Error + Send + Sync + 'static,
) -> OCRError
pub fn model_inference_error( model_name: &str, operation: &str, batch_index: usize, input_shape: &[usize], context: &str, error: impl Error + Send + Sync + 'static, ) -> OCRError
Creates an OCRError for model inference operations with detailed context.
§Arguments
model_name- The name of the model where inference failed.operation- The operation that failed.batch_index- The batch index where the error occurred.input_shape- The input tensor shape.context- Additional context about the error.error- The underlying error that caused this error.
§Returns
An OCRError instance.
Sourcepub fn model_inference_error_builder(
model_name: impl Into<String>,
operation: impl Into<String>,
) -> ModelInferenceErrorBuilder
pub fn model_inference_error_builder( model_name: impl Into<String>, operation: impl Into<String>, ) -> ModelInferenceErrorBuilder
Creates a builder for constructing model inference errors with optional context pieces.
Sourcepub fn inference_error(
model_name: &str,
context: &str,
error: impl Error + Send + Sync + 'static,
) -> OCRError
pub fn inference_error( model_name: &str, context: &str, error: impl Error + Send + Sync + 'static, ) -> OCRError
Creates an OCRError for inference operations with model context (simple variant).
This is an alias for inference_with_context which wraps a simple model inference error.
For detailed inference errors, use model_inference_error directly.
§Arguments
model_name- The name of the model where inference failed.context- Additional context about the error.error- The underlying error that caused this error.
§Returns
An OCRError instance.
Sourcepub fn model_load_error(
model_path: impl AsRef<Path>,
reason: impl Into<String>,
suggestion: Option<&str>,
source: Option<impl Error + Send + Sync + 'static>,
) -> OCRError
pub fn model_load_error( model_path: impl AsRef<Path>, reason: impl Into<String>, suggestion: Option<&str>, source: Option<impl Error + Send + Sync + 'static>, ) -> OCRError
Creates an OCRError for model load failures with contextual suggestions.
§Arguments
model_path- Path to the model filereason- Short reason descriptionsuggestion- Optional suggestion message (without punctuation)source- Optional underlying error
Sourcepub fn tensor_operation_error(
operation: &str,
expected_shape: &[usize],
actual_shape: &[usize],
context: &str,
error: impl Error + Send + Sync + 'static,
) -> OCRError
pub fn tensor_operation_error( operation: &str, expected_shape: &[usize], actual_shape: &[usize], context: &str, error: impl Error + Send + Sync + 'static, ) -> OCRError
Creates an OCRError for tensor operations with detailed shape information.
§Arguments
operation- The tensor operation that failed.expected_shape- The expected tensor shape.actual_shape- The actual tensor shape.context- Additional context about where the error occurred.error- The underlying error that caused this error.
§Returns
An OCRError instance.
Sourcepub fn batch_processing_error(
stage: ProcessingStage,
batch_index: usize,
batch_size: usize,
operation: &str,
error: impl Error + Send + Sync + 'static,
) -> OCRError
pub fn batch_processing_error( stage: ProcessingStage, batch_index: usize, batch_size: usize, operation: &str, error: impl Error + Send + Sync + 'static, ) -> OCRError
Creates an OCRError for batch processing operations with detailed context.
§Arguments
stage- The processing stage where the error occurred.batch_index- The index of the batch item that failed.batch_size- The total size of the batch.operation- The operation that failed.error- The underlying error that caused this error.
§Returns
An OCRError instance.
Sourcepub fn pipeline_stage_error(
stage_name: &str,
stage_id: &str,
input_count: usize,
operation: &str,
error: impl Error + Send + Sync + 'static,
) -> OCRError
pub fn pipeline_stage_error( stage_name: &str, stage_id: &str, input_count: usize, operation: &str, error: impl Error + Send + Sync + 'static, ) -> OCRError
Creates an OCRError for pipeline stage operations with detailed context.
§Arguments
stage_name- The name of the pipeline stage.stage_id- The ID of the pipeline stage.input_count- The number of input items.operation- The operation that failed.error- The underlying error that caused this error.
§Returns
An OCRError instance.
Source§impl OCRError
Helper functions for creating consistent batch processing errors
impl OCRError
Helper functions for creating consistent batch processing errors
Sourcepub fn batch_item_error(
stage_name: &str,
batch_context: Option<&str>,
item_index: usize,
total_items: Option<usize>,
operation: &str,
error: impl Error + Send + Sync + 'static,
) -> OCRError
pub fn batch_item_error( stage_name: &str, batch_context: Option<&str>, item_index: usize, total_items: Option<usize>, operation: &str, error: impl Error + Send + Sync + 'static, ) -> OCRError
Creates a standardized error for batch item processing failures.
This helper reduces code duplication and ensures consistent error formatting across different batch processing contexts (orientation, recognition, etc.).
§Arguments
stage_name- The name of the processing stage (e.g., “orientation”, “recognition”)batch_context- Additional context about the batch (e.g., batch ID, group name)item_index- The index of the failed item within the batchtotal_items- Total number of items in the batch (if known)operation- The specific operation that failederror- The underlying error
§Returns
A formatted OCRError with consistent batch processing context
Sourcepub fn format_batch_error_message(
stage_name: &str,
batch_context: &str,
affected_indices: &[usize],
error: &dyn Error,
) -> String
pub fn format_batch_error_message( stage_name: &str, batch_context: &str, affected_indices: &[usize], error: &dyn Error, ) -> String
Creates a standardized error message for batch processing failures.
This helper creates formatted error messages without wrapping in OCRError, useful for logging and warning messages.
§Arguments
stage_name- The name of the processing stagebatch_context- Additional context about the batchaffected_indices- Indices of items affected by the failureerror- The underlying error
§Returns
A formatted error message string
Source§impl OCRError
impl OCRError
Sourcepub fn config_error_detailed(
context: impl Into<String>,
details: impl Into<String>,
) -> OCRError
pub fn config_error_detailed( context: impl Into<String>, details: impl Into<String>, ) -> OCRError
Creates a configuration error with enhanced context and details.
§Arguments
context- High-level description of what was being configureddetails- Specific details about what went wrong
§Returns
A new ConfigError with enhanced context
§Example
let err = OCRError::config_error_detailed(
"task graph validation",
"task 'recognition' depends on 'detection' which does not exist"
);
assert!(matches!(err, OCRError::ConfigError { .. }));Sourcepub fn config_error_with_suggestion(
context: impl Into<String>,
details: impl Into<String>,
suggestion: impl Into<String>,
) -> OCRError
pub fn config_error_with_suggestion( context: impl Into<String>, details: impl Into<String>, suggestion: impl Into<String>, ) -> OCRError
Creates a configuration error with a suggestion for recovery.
§Arguments
context- High-level description of what was being configureddetails- Specific details about what went wrongsuggestion- Suggestion for how to fix the issue
§Returns
A new ConfigError with enhanced context and suggestion
§Example
let err = OCRError::config_error_with_suggestion(
"model loading",
"model file not found at 'models/detection.onnx'",
"ensure the model has been downloaded and the path is correct"
);
assert!(matches!(err, OCRError::ConfigError { .. }));Sourcepub fn invalid_field(
field: impl Into<String>,
expected: impl Into<String>,
actual: impl Into<String>,
) -> OCRError
pub fn invalid_field( field: impl Into<String>, expected: impl Into<String>, actual: impl Into<String>, ) -> OCRError
Sourcepub fn type_mismatch(
task_id: impl Into<String>,
expected: impl Into<String>,
actual: impl Into<String>,
) -> OCRError
pub fn type_mismatch( task_id: impl Into<String>, expected: impl Into<String>, actual: impl Into<String>, ) -> OCRError
Trait Implementations§
Source§impl Error for OCRError
impl Error for OCRError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl From<ConfigError> for OCRError
impl From<ConfigError> for OCRError
Source§fn from(error: ConfigError) -> OCRError
fn from(error: ConfigError) -> OCRError
Converts a ConfigError to OCRError::ConfigError.
Source§impl From<ImageError> for OCRError
impl From<ImageError> for OCRError
Source§fn from(error: ImageError) -> OCRError
fn from(error: ImageError) -> OCRError
Converts an image::ImageError to OCRError::ImageLoad.
Source§impl From<ImageProcessError> for OCRError
impl From<ImageProcessError> for OCRError
Source§fn from(error: ImageProcessError) -> OCRError
fn from(error: ImageProcessError) -> OCRError
Converts an ImageProcessError to OCRError::Processing.
Source§impl From<ShapeError> for OCRError
impl From<ShapeError> for OCRError
Source§fn from(source: ShapeError) -> OCRError
fn from(source: ShapeError) -> OCRError
Auto Trait Implementations§
impl Freeze for OCRError
impl !RefUnwindSafe for OCRError
impl Send for OCRError
impl Sync for OCRError
impl Unpin for OCRError
impl !UnwindSafe for OCRError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more