Skip to main content

llvm_bitcode/
error.rs

1//! Bitcode error types.
2
3/// Error type for bitcode reading and writing.
4#[derive(Debug)]
5pub enum BitcodeError {
6    /// Magic bytes did not match the LRIR format header.
7    InvalidMagic,
8    /// Input ended before a field could be fully read.
9    TruncatedInput,
10    /// Unexpected end-of-file inside a structured record.
11    UnexpectedEof,
12    /// A record type tag was not recognised.
13    UnsupportedRecord(u32),
14    /// A type tag was not a recognised `TypeTag` value.
15    InvalidType,
16    /// A general parse error with a description.
17    ParseError(String),
18}
19
20impl std::fmt::Display for BitcodeError {
21    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22        match self {
23            BitcodeError::InvalidMagic => write!(f, "invalid magic bytes (not LRIR format)"),
24            BitcodeError::TruncatedInput => write!(f, "input is truncated"),
25            BitcodeError::UnexpectedEof => write!(f, "unexpected end of file"),
26            BitcodeError::UnsupportedRecord(t) => write!(f, "unsupported record type: {}", t),
27            BitcodeError::InvalidType => write!(f, "invalid type tag"),
28            BitcodeError::ParseError(msg) => write!(f, "parse error: {}", msg),
29        }
30    }
31}
32
33impl std::error::Error for BitcodeError {}