Skip to main content

CsvError

Enum CsvError 

Source
pub enum CsvError {
Show 16 variants ParseError { line: usize, message: String, }, TypeMismatch { column: String, expected: String, value: String, }, MissingColumn(String), InvalidHeader { position: usize, reason: String, }, WidthMismatch { expected: usize, actual: usize, row: usize, }, Io(Error), CsvLib(Error), HedlCore(String), SecurityLimit { limit: usize, actual: usize, }, EmptyId { row: usize, }, ListNotFound { name: String, available: String, }, NotAList { name: String, actual_type: String, }, NoLists, InvalidUtf8 { context: String, }, Other(String), Security { limit_type: String, limit: usize, actual: usize, message: String, },
}
Expand description

CSV conversion error types.

This enum provides structured error handling for CSV parsing and generation, with contextual information to help diagnose issues.

§Examples

use hedl_csv::CsvError;

let err = CsvError::TypeMismatch {
    column: "age".to_string(),
    expected: "integer".to_string(),
    value: "abc".to_string(),
};

assert_eq!(
    err.to_string(),
    "Type mismatch in column 'age': expected integer, got 'abc'"
);

Variants§

§

ParseError

CSV parsing error at a specific line.

§Examples

use hedl_csv::CsvError;

let err = CsvError::ParseError {
    line: 42,
    message: "Invalid escape sequence".to_string(),
};
assert!(err.to_string().contains("line 42"));

Fields

§line: usize

Line number where the error occurred (1-based).

§message: String

Detailed error message.

§

TypeMismatch

Type mismatch when converting values.

This error occurs when a CSV field value cannot be converted to the expected type.

§Examples

use hedl_csv::CsvError;

let err = CsvError::TypeMismatch {
    column: "price".to_string(),
    expected: "float".to_string(),
    value: "not-a-number".to_string(),
};

Fields

§column: String

Column name where the mismatch occurred.

§expected: String

Expected type description.

§value: String

Actual value that failed to convert.

§

MissingColumn(String)

Missing required column in CSV data.

§Examples

use hedl_csv::CsvError;

let err = CsvError::MissingColumn("id".to_string());
assert_eq!(err.to_string(), "Missing required column: id");
§

InvalidHeader

Invalid header format or content.

§Examples

use hedl_csv::CsvError;

let err = CsvError::InvalidHeader {
    position: 0,
    reason: "Empty column name".to_string(),
};

Fields

§position: usize

Position of the invalid header (0-based).

§reason: String

Reason the header is invalid.

§

WidthMismatch

Row has wrong number of columns.

§Examples

use hedl_csv::CsvError;

let err = CsvError::WidthMismatch {
    expected: 5,
    actual: 3,
    row: 10,
};
assert!(err.to_string().contains("expected 5 columns"));
assert!(err.to_string().contains("got 3"));

Fields

§expected: usize

Expected number of columns.

§actual: usize

Actual number of columns in the row.

§row: usize

Row number where the mismatch occurred (1-based).

§

Io(Error)

I/O error during CSV reading or writing.

§Examples

use hedl_csv::CsvError;
use std::io;

let io_err = io::Error::new(io::ErrorKind::NotFound, "file not found");
let csv_err = CsvError::from(io_err);
§

CsvLib(Error)

Error from underlying CSV library.

§Examples

use hedl_csv::CsvError;

// This error type wraps csv::Error transparently
§

HedlCore(String)

HEDL core error during conversion.

This wraps errors from the hedl_core crate when they occur during CSV conversion operations.

§

SecurityLimit

Row count exceeded security limit.

§Examples

use hedl_csv::CsvError;

let err = CsvError::SecurityLimit {
    limit: 1_000_000,
    actual: 1_000_001,
};
assert!(err.to_string().contains("Security limit"));

Fields

§limit: usize

Maximum allowed rows.

§actual: usize

Actual row count encountered.

§

EmptyId

Empty ID field in CSV data.

§Examples

use hedl_csv::CsvError;

let err = CsvError::EmptyId { row: 5 };
assert_eq!(err.to_string(), "Empty 'id' field at row 5");

Fields

§row: usize

Row number with empty ID (1-based).

§

ListNotFound

Matrix list not found in document.

§Examples

use hedl_csv::CsvError;

let err = CsvError::ListNotFound {
    name: "people".to_string(),
    available: "users, items".to_string(),
};
assert!(err.to_string().contains("not found"));

Fields

§name: String

Name of the list that was not found.

§available: String

Available list names in the document.

§

NotAList

Item is not a matrix list.

§Examples

use hedl_csv::CsvError;

let err = CsvError::NotAList {
    name: "value".to_string(),
    actual_type: "scalar".to_string(),
};

Fields

§name: String

Name of the item.

§actual_type: String

Actual type of the item.

§

NoLists

No matrix lists found in document.

§

InvalidUtf8

Invalid UTF-8 in CSV output.

§Examples

use hedl_csv::CsvError;

let err = CsvError::InvalidUtf8 {
    context: "CSV serialization".to_string(),
};

Fields

§context: String

Context where the invalid UTF-8 was encountered.

§

Other(String)

Generic error with custom message.

This is a catch-all for errors that don’t fit other categories.

§

Security

Security limit violated.

This error occurs when CSV data exceeds configured security limits to prevent denial-of-service attacks.

§Examples

use hedl_csv::CsvError;

let err = CsvError::Security {
    limit_type: "column count".to_string(),
    limit: 10_000,
    actual: 15_000,
    message: "CSV has 15000 columns, exceeds limit of 10000".to_string(),
};
assert!(err.to_string().contains("Security limit"));

Fields

§limit_type: String

Type of limit that was violated.

§limit: usize

Configured limit value.

§actual: usize

Actual value encountered.

§message: String

Detailed error message.

Implementations§

Source§

impl CsvError

Source

pub fn with_context(self, context: String) -> Self

Add context to an error message.

This is useful for providing additional information about where an error occurred.

§Examples
use hedl_csv::CsvError;

let err = CsvError::ParseError {
    line: 5,
    message: "Invalid value".to_string(),
};
let with_context = err.with_context("in column 'age' at line 10".to_string());
Source

pub fn security(message: String, _line: usize) -> Self

Create a security error for limit violations.

This is a convenience method for creating Security error variants.

§Examples
use hedl_csv::CsvError;

let err = CsvError::security(
    "CSV has 15000 columns, exceeds limit of 10000".to_string(),
    0
);
assert!(matches!(err, CsvError::Security { .. }));

Trait Implementations§

Source§

impl Debug for CsvError

Source§

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

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

impl Display for CsvError

Source§

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

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

impl Error for CsvError

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<Error> for CsvError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for CsvError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<HedlError> for CsvError

Source§

fn from(err: HedlError) -> Self

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, 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> 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.