#[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::Displayfor user messages - Debuggable: Implement
std::fmt::Debugfor 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
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_timestampsis 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::Binaryfor non-text data - Validate encoding before ingest
- Use encoding detection libraries (e.g.,
chardetng) - Use
String::from_utf8_lossyand convert toText
§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:
IngestConfig::max_payload_bytes(raw size)IngestConfig::max_normalized_bytes(after normalization)
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
impl IngestError
Sourcepub fn is_client_error(&self) -> bool
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());Sourcepub fn http_status_code(&self) -> u16
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
impl Clone for IngestError
Source§fn clone(&self) -> IngestError
fn clone(&self) -> IngestError
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more