Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Error Handling

Each crate in warcraft-rs defines its own error type using thiserror. There is no shared error type across crates.

Error Types by Crate

CrateError TypeModule
wow-mpqErrorwow_mpq::error
wow-blpLoadError, EncodeError, ConvertErrorwow_blp::parser, wow_blp::encode, wow_blp::convert
wow-m2M2Errorwow_m2::error
wow-wmoWmoErrorwow_wmo::error
wow-adtAdtErrorwow_adt::error
wow-wdlWdlErrorwow_wdl::error
wow-wdtErrorwow_wdt::error
wow-cdbcErrorwow_cdbc (re-exported at crate root)

Pattern

All error types follow the same pattern:

#![allow(unused)]
fn main() {
use thiserror::Error;

#[derive(Error, Debug)]
pub enum Error {
    #[error("I/O error: {0}")]
    Io(#[from] std::io::Error),

    #[error("Invalid format: {0}")]
    InvalidFormat(String),

    // Format-specific variants...
}

pub type Result<T> = std::result::Result<T, Error>;
}

Each crate also provides a Result<T> type alias for convenience.

Usage

#![allow(unused)]
fn main() {
use wow_mpq::Archive;

fn read_file() -> Result<Vec<u8>, wow_mpq::error::Error> {
    let mut archive = Archive::open("archive.mpq")?;
    let data = archive.read_file("Interface/FrameXML/UIParent.lua")?;
    Ok(data)
}
}

The CLI application (warcraft-rs) uses anyhow for error handling, converting library errors via the ? operator.

See Also