Files
cursebreaker-parser-rust/src/error.rs
2025-12-30 23:13:12 +09:00

75 lines
2.0 KiB
Rust

use std::path::PathBuf;
use thiserror::Error;
/// Result type alias for parser operations
pub type Result<T> = std::result::Result<T, Error>;
/// Errors that can occur during Unity file parsing
#[derive(Error, Debug)]
pub enum Error {
/// IO error when reading files
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
/// YAML parsing error
#[error("YAML parsing error: {0}")]
Yaml(#[from] serde_yaml::Error),
/// Invalid Unity file format
#[error("Invalid Unity file format: {0}")]
InvalidFormat(String),
/// Missing required Unity header
#[error("Missing required Unity YAML header in file: {}", .0.display())]
MissingHeader(PathBuf),
/// Invalid Unity type tag
#[error("Invalid Unity type tag: {0}")]
InvalidTypeTag(String),
/// Invalid anchor ID
#[error("Invalid anchor ID: {0}")]
InvalidAnchor(String),
/// Missing document in file
#[error("No documents found in Unity file")]
EmptyFile,
/// Reference resolution error
#[error("Failed to resolve reference: {0}")]
ReferenceError(String),
/// Property not found
#[error("Property not found: {0}")]
PropertyNotFound(String),
/// Type conversion error
#[error("Type conversion error: expected {expected}, found {found}")]
TypeMismatch { expected: String, found: String },
/// Property value conversion error
#[error("Failed to convert property value from {from} to {to}")]
PropertyConversion { from: String, to: String },
/// Invalid property path
#[error("Invalid property path: {0}")]
InvalidPropertyPath(String),
}
impl Error {
/// Create an invalid format error
pub fn invalid_format(msg: impl Into<String>) -> Self {
Error::InvalidFormat(msg.into())
}
/// Create a reference error
pub fn reference_error(msg: impl Into<String>) -> Self {
Error::ReferenceError(msg.into())
}
/// Create a property not found error
pub fn property_not_found(msg: impl Into<String>) -> Self {
Error::PropertyNotFound(msg.into())
}
}