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
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
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
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
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 transparentlyHedlCore(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"));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");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
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(),
};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(),
};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"));Implementations§
Source§impl CsvError
impl CsvError
Sourcepub fn with_context(self, context: String) -> Self
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());Sourcepub fn security(message: String, _line: usize) -> Self
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 { .. }));