Skip to main content

OCRError

Enum OCRError 

Source
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: ProcessingStage

The stage of processing where the error occurred.

§context: String

Additional context about the error.

§source: Box<dyn Error + Sync + Send>

The underlying error that caused this error.

§

Inference

Error occurred during inference.

Fields

§model_name: String

The name of the model where inference failed.

§context: String

Additional context about the inference error.

§source: Box<dyn Error + Sync + Send>

The underlying error that caused this error.

§

ModelInference

Error occurred during model inference with detailed context.

Fields

§model_name: String

The name of the model where inference failed.

§operation: String

The operation that failed (e.g., “forward_pass”, “preprocessing”).

§batch_index: usize

The batch index where the error occurred.

§input_shape: Vec<usize>

The input tensor shape.

§context: String

Additional context about the error.

§source: Box<dyn Error + Sync + Send>

The underlying error that caused this error.

§

InvalidInput

Error indicating invalid input.

Fields

§message: String

A message describing the invalid input.

§

ConfigError

Error indicating a configuration problem.

Fields

§message: String

A message describing the configuration error.

§

BufferTooSmall

Error indicating a buffer is too small.

Fields

§expected: usize

The expected minimum buffer size.

§actual: usize

The actual buffer size.

§

Session(Error)

Error from the ONNX Runtime session.

§

TensorOperation

Error from tensor operations with detailed context.

Fields

§operation: String

The tensor operation that failed.

§expected_shape: Vec<usize>

The expected tensor shape.

§actual_shape: Vec<usize>

The actual tensor shape.

§context: String

Additional context about where the error occurred.

§source: Box<dyn Error + Sync + Send>

The underlying error that caused this error.

§

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.

Fields

§model_path: String

Path to the model that failed to load

§reason: String

Short reason string

§suggestion: String

Optional suggestion (prefixed with ’; ’ when present)

§source: Option<Box<dyn Error + Sync + Send>>

Underlying source error

Implementations§

Source§

impl OCRError

Implementation of OCRError with utility functions for creating errors.

Source

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.

Source

pub fn post_processing( context: &str, error: impl Error + Send + Sync + 'static, ) -> OCRError

Creates an OCRError for post-processing operations.

§Arguments
  • context - Additional context about the error.
  • error - The underlying error that caused this error.
§Returns

An OCRError instance.

Source

pub fn normalization( context: &str, error: impl Error + Send + Sync + 'static, ) -> OCRError

Creates an OCRError for normalization operations.

§Arguments
  • context - Additional context about the error.
  • error - The underlying error that caused this error.
§Returns

An OCRError instance.

Source

pub fn resize_error( context: &str, error: impl Error + Send + Sync + 'static, ) -> OCRError

Creates an OCRError for resize operations.

§Arguments
  • context - Additional context about the error.
  • error - The underlying error that caused this error.
§Returns

An OCRError instance.

Source

pub fn image_processing( context: &str, error: impl Error + Send + Sync + 'static, ) -> OCRError

Creates an OCRError for image processing operations.

§Arguments
  • context - Additional context about the error.
  • error - The underlying error that caused this error.
§Returns

An OCRError instance.

Source

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.

Source

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.

Source

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.

Source

pub fn basic_inference_error( error: impl Error + Send + Sync + 'static, ) -> OCRError

Creates an OCRError for basic inference operations (legacy method).

§Arguments
  • error - The underlying error that caused this error.
§Returns

An OCRError instance.

Source

pub fn invalid_input(message: impl Into<String>) -> OCRError

Creates an OCRError for invalid input.

§Arguments
  • message - A message describing the invalid input.
§Returns

An OCRError instance.

Source

pub fn config_error(message: impl Into<String>) -> OCRError

Creates an OCRError for configuration errors.

§Arguments
  • message - A message describing the configuration error.
§Returns

An OCRError instance.

Source

pub fn config_error_with_context( field: &str, value: &str, reason: &str, ) -> OCRError

Creates an OCRError for configuration errors with context.

§Arguments
  • field - The field where the error occurred.
  • value - The value of the field.
  • reason - The reason for the error.
§Returns

An OCRError instance.

Source

pub fn validation_error( component: &str, field: &str, expected: &str, actual: &str, ) -> OCRError

Creates an OCRError for validation errors.

§Arguments
  • component - The component where the error occurred.
  • field - The field where the error occurred.
  • expected - The expected value.
  • actual - The actual value.
§Returns

An OCRError instance.

Source

pub fn resource_limit_error( resource: &str, limit: usize, requested: usize, ) -> OCRError

Creates an OCRError for resource limit errors.

§Arguments
  • resource - The resource that exceeded its limit.
  • limit - The maximum allowed limit.
  • requested - The requested amount.
§Returns

An OCRError instance.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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 file
  • reason - Short reason description
  • suggestion - Optional suggestion message (without punctuation)
  • source - Optional underlying error
Source

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.

Source

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.

Source

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

Source

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 batch
  • total_items - Total number of items in the batch (if known)
  • operation - The specific operation that failed
  • error - The underlying error
§Returns

A formatted OCRError with consistent batch processing context

Source

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 stage
  • batch_context - Additional context about the batch
  • affected_indices - Indices of items affected by the failure
  • error - The underlying error
§Returns

A formatted error message string

Source§

impl OCRError

Source

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 configured
  • details - 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 { .. }));
Source

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 configured
  • details - Specific details about what went wrong
  • suggestion - 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 { .. }));
Source

pub fn missing_field( field: impl Into<String>, context: impl Into<String>, ) -> OCRError

Creates a configuration error for missing required fields.

§Arguments
  • field - The name of the missing field
  • context - Context about where the field is required
§Returns

A new ConfigError for missing fields

Source

pub fn invalid_field( field: impl Into<String>, expected: impl Into<String>, actual: impl Into<String>, ) -> OCRError

Creates a configuration error for invalid field values.

§Arguments
  • field - The name of the field with an invalid value
  • expected - Description of what was expected
  • actual - Description of what was actually provided
§Returns

A new ConfigError for invalid field values

Source

pub fn type_mismatch( task_id: impl Into<String>, expected: impl Into<String>, actual: impl Into<String>, ) -> OCRError

Creates a configuration error for type mismatches in task graphs.

§Arguments
  • task_id - The ID of the task with the mismatch
  • expected - The expected type
  • actual - The actual type
§Returns

A new ConfigError for type mismatches

Source

pub fn dependency_error( dependent: impl Into<String>, dependency: impl Into<String>, issue: impl Into<String>, ) -> OCRError

Creates a configuration error for dependency issues.

§Arguments
  • dependent - The task that has a dependency
  • dependency - The missing or invalid dependency
  • issue - Description of the issue
§Returns

A new ConfigError for dependency issues

Source

pub fn adapter_execution_error( adapter: impl Into<String>, context: impl Into<String>, source: impl Error + Send + Sync + 'static, ) -> OCRError

Wraps an error that occurred while executing a model adapter.

Trait Implementations§

Source§

impl Debug for OCRError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Display for OCRError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Error for OCRError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<ConfigError> for OCRError

Source§

fn from(error: ConfigError) -> OCRError

Converts a ConfigError to OCRError::ConfigError.

Source§

impl From<Error> for OCRError

Source§

fn from(source: Error) -> OCRError

Converts to this type from the input type.
Source§

impl From<Error> for OCRError

Source§

fn from(source: Error) -> OCRError

Converts to this type from the input type.
Source§

impl From<ImageError> for OCRError

Source§

fn from(error: ImageError) -> OCRError

Converts an image::ImageError to OCRError::ImageLoad.

Source§

impl From<ImageProcessError> for OCRError

Source§

fn from(error: ImageProcessError) -> OCRError

Converts an ImageProcessError to OCRError::Processing.

Source§

impl From<ShapeError> for OCRError

Source§

fn from(source: ShapeError) -> OCRError

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToCompactString for T
where T: Display,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more