toon_codec/error
Error types and utility functions for TOON encoding/decoding.
This module defines all error types that can occur during TOON operations and provides helper functions for error formatting and handling. Comprehensive error type for TOON operations.
Each variant provides context about what went wrong, including line numbers and positions where applicable for better error reporting. Convert a ToonError to a human-readable error message.
Examples
let error = MissingColon(line: 5)
error_to_string(error)
// -> "Missing colon after key at line 5"
Create a parse error with context. Create a validation error. Create a structure error. Create an invalid escape error. Create an unterminated string error. Create a count mismatch error. Create an indentation error. Create a missing colon error. Create an invalid header error. Create a delimiter mismatch error.
Types
pub type ToonError {
ParseError(message: String, line: Int, column: Int)
ValidationError(message: String)
StructureError(message: String)
InvalidEscape(sequence: String, position: Int)
UnterminatedString(position: Int)
CountMismatch(expected: Int, actual: Int, context: String)
IndentationError(message: String, line: Int)
MissingColon(line: Int)
EmptyInput
InvalidHeader(message: String, line: Int)
DelimiterMismatch(expected: String, line: Int)
}
Constructors
-
ParseError(message: String, line: Int, column: Int)Generic parsing error with message, line, and column
-
ValidationError(message: String)Validation error (e.g., invalid structure or format)
-
StructureError(message: String)Structure error (e.g., unexpected indentation)
-
InvalidEscape(sequence: String, position: Int)Invalid escape sequence in a quoted string
-
UnterminatedString(position: Int)Unterminated string (missing closing quote)
-
CountMismatch(expected: Int, actual: Int, context: String)Array/row count doesn’t match declared length
-
IndentationError(message: String, line: Int)Invalid indentation (not a multiple of indent_size in strict mode)
-
MissingColon(line: Int)Missing colon after a key
-
EmptyInputEmpty input document
-
InvalidHeader(message: String, line: Int)Invalid header format
-
DelimiterMismatch(expected: String, line: Int)Delimiter mismatch in array/tabular data
Values
pub fn count_mismatch(
expected: Int,
actual: Int,
context: String,
) -> ToonError
pub fn delimiter_mismatch(
expected: String,
line: Int,
) -> ToonError
pub fn error_to_string(error: ToonError) -> String
pub fn indentation_error(message: String, line: Int) -> ToonError
pub fn invalid_escape(
sequence: String,
position: Int,
) -> ToonError
pub fn invalid_header(message: String, line: Int) -> ToonError
pub fn missing_colon(line: Int) -> ToonError
pub fn parse_error(
message: String,
line: Int,
column: Int,
) -> ToonError
pub fn structure_error(message: String) -> ToonError
pub fn unterminated_string(position: Int) -> ToonError
pub fn validation_error(message: String) -> ToonError