mirror of
https://github.com/Yuyi-Oak/BlueArchiveToolkit.git
synced 2026-09-18 12:14:56 +08:00
53 lines
1.3 KiB
Rust
53 lines
1.3 KiB
Rust
//! AssetBundle error types.
|
|
|
|
use thiserror::Error;
|
|
|
|
/// AssetBundle parser error.
|
|
#[derive(Error, Debug)]
|
|
pub enum AssetBundleError {
|
|
/// I/O error.
|
|
#[error("IO error: {0}")]
|
|
Io(#[from] std::io::Error),
|
|
|
|
/// Parser reached malformed data while reading a named field.
|
|
#[error("Parse error at offset {offset} while reading {field}: {message}")]
|
|
ParseField {
|
|
/// Field or structure name being read.
|
|
field: String,
|
|
/// Byte offset where parsing failed.
|
|
offset: usize,
|
|
/// Human-readable diagnostic.
|
|
message: String,
|
|
},
|
|
|
|
/// General parser error.
|
|
#[error("Parse error: {0}")]
|
|
Parse(String),
|
|
|
|
/// Unsupported format or compression mode.
|
|
#[error("Unsupported format: {0}")]
|
|
UnsupportedFormat(String),
|
|
|
|
/// Other error.
|
|
#[error(transparent)]
|
|
Other(#[from] anyhow::Error),
|
|
}
|
|
|
|
impl AssetBundleError {
|
|
/// Creates a field-scoped parser error with byte offset context.
|
|
pub fn parse_field(
|
|
field: impl Into<String>,
|
|
offset: usize,
|
|
message: impl Into<String>,
|
|
) -> Self {
|
|
Self::ParseField {
|
|
field: field.into(),
|
|
offset,
|
|
message: message.into(),
|
|
}
|
|
}
|
|
}
|
|
|
|
/// AssetBundle result type.
|
|
pub type Result<T> = std::result::Result<T, AssetBundleError>;
|