Skip to main content

IngestError

Enum IngestError 

Source
#[non_exhaustive]
pub enum IngestError { MissingPayload, EmptyBinaryPayload, InvalidMetadata(String), InvalidUtf8(String), EmptyNormalizedText, PayloadTooLarge(String), }
Expand description

Errors that can occur during ingest normalization and validation.

These errors represent validation failures that prevent content from being ingested. All variants are:

  • Cloneable: Can be copied for error propagation
  • Comparable: Support equality checks for testing
  • Displayable: Implement std::fmt::Display for user messages
  • Debuggable: Implement std::fmt::Debug for development

The enum is marked #[non_exhaustive] to allow future additions without breaking existing code. Callers should always include a catch-all arm when matching.

§Examples

use ingest::IngestError;

// Error messages
let err = IngestError::MissingPayload;
assert_eq!(err.to_string(), "missing payload for source that requires payload");

let err = IngestError::InvalidMetadata("tenant required".to_string());
assert!(err.to_string().contains("tenant required"));

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

MissingPayload

Missing payload for source that requires one.

This error occurs when a source type (e.g., RawText, File) requires a payload but None was provided.

§Example

use ingest::{ingest, IngestConfig, IngestError};
use ingest::{RawIngestRecord, IngestMetadata, IngestSource};

let record = RawIngestRecord {
    id: "test".to_string(),
    source: IngestSource::RawText, // Requires payload
    metadata: IngestMetadata {
        tenant_id: Some("t".to_string()),
        doc_id: Some("d".to_string()),
        received_at: None,
        original_source: None,
        attributes: None,
    },
    payload: None, // ERROR: Required but missing
};

// This will fail with MissingPayload
// let result = ingest(record, &IngestConfig::default());
§

EmptyBinaryPayload

Binary payload is empty (zero bytes).

This error occurs when IngestPayload::Binary contains an empty vector. Empty binary payloads are rejected to prevent meaningless ingests.

§Example

use ingest::IngestPayload;

// This will be rejected
let empty_binary = IngestPayload::Binary(vec![]);
§

InvalidMetadata(String)

Invalid metadata or policy violation.

This is a catch-all error for metadata validation failures:

  • Required field missing (per MetadataPolicy)
  • Attributes exceed size limit
  • Future timestamp (when reject_future_timestamps is enabled)
  • Empty required field after sanitization
  • Invalid source/payload combination

The message provides details about the specific violation.

§Example

use ingest::IngestError;

let err = IngestError::InvalidMetadata(
    "tenant_id is required by ingest policy".to_string()
);
§

InvalidUtf8(String)

Invalid UTF-8 in TextBytes payload.

This error occurs when IngestPayload::TextBytes contains bytes that cannot be decoded as valid UTF-8.

§Solutions

  • Use IngestPayload::Binary for non-text data
  • Validate encoding before ingest
  • Use encoding detection libraries (e.g., chardetng)
  • Use String::from_utf8_lossy and convert to Text

§Example

use ingest::{IngestPayload, ingest, IngestConfig, IngestError};
use ingest::{RawIngestRecord, IngestMetadata, IngestSource};

let record = RawIngestRecord {
    id: "test".to_string(),
    source: IngestSource::RawText,
    metadata: IngestMetadata {
        tenant_id: Some("t".to_string()),
        doc_id: Some("d".to_string()),
        received_at: None,
        original_source: None,
        attributes: None,
    },
    payload: Some(IngestPayload::TextBytes(vec![0xFF, 0xFE])), // Invalid UTF-8
};

// This will fail with InvalidUtf8
// let result = ingest(record, &IngestConfig::default());
§

EmptyNormalizedText

Text payload became empty after normalization.

This error occurs when normalize_payload() produces an empty string, typically because:

  • Input was whitespace-only (e.g., " ", "\n\n")
  • Input contained only control characters (which were stripped)
  • Input was empty string

§Solutions

  • Check input before ingest: if content.trim().is_empty()
  • Provide meaningful error messages to users
  • Consider rejecting at API layer before calling ingest

§Example

use ingest::{ingest, IngestConfig, IngestError, IngestPayload};
use ingest::{RawIngestRecord, IngestMetadata, IngestSource};

let record = RawIngestRecord {
    id: "test".to_string(),
    source: IngestSource::RawText,
    metadata: IngestMetadata {
        tenant_id: Some("t".to_string()),
        doc_id: Some("d".to_string()),
        received_at: None,
        original_source: None,
        attributes: None,
    },
    payload: Some(IngestPayload::Text("   \n\t   ".to_string())), // Whitespace only
};

// This will fail with EmptyNormalizedText
// let result = ingest(record, &IngestConfig::default());
§

PayloadTooLarge(String)

Payload exceeds configured size limit.

This error occurs when a payload violates:

The message contains details about which limit was exceeded and by how much.

§HTTP Status Code

This error should map to 413 Payload Too Large in HTTP contexts.

§Solutions

  • Increase limits if appropriate
  • Reject at API layer before calling ingest
  • Implement chunked processing for large documents

§Example

use ingest::{IngestConfig, IngestError};

let err = IngestError::PayloadTooLarge(
    "raw payload size 15000000 exceeds limit of 10000000".to_string()
);

// Map to HTTP status
let status = match err {
    IngestError::PayloadTooLarge(_) => 413,
    _ => 400,
};

Implementations§

Source§

impl IngestError

Source

pub fn is_client_error(&self) -> bool

Returns true if this error indicates a client-side issue.

All ingest errors are client-side issues (invalid input), so this always returns true. It is provided for API consistency with other error types that might have server-side variants.

§Example
use ingest::IngestError;

let err = IngestError::MissingPayload;
assert!(err.is_client_error());
Source

pub fn http_status_code(&self) -> u16

Returns a suggested HTTP status code for this error.

This is a convenience method for HTTP API implementations.

§Status Codes
  • PayloadTooLarge: 413
  • All others: 400
§Example
use ingest::IngestError;

let err = IngestError::PayloadTooLarge("too big".to_string());
assert_eq!(err.http_status_code(), 413);

let err = IngestError::MissingPayload;
assert_eq!(err.http_status_code(), 400);

Trait Implementations§

Source§

impl Clone for IngestError

Source§

fn clone(&self) -> IngestError

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for IngestError

Source§

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

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

impl Display for IngestError

Source§

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

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

impl Error for IngestError

1.30.0 · 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 PartialEq for IngestError

Source§

fn eq(&self, other: &IngestError) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for IngestError

Source§

impl StructuralPartialEq for IngestError

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<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