ferro_babe/error.rs
1use rust_asm::error::ClassReadError;
2use thiserror::Error;
3
4#[derive(Debug, Error)]
5/// Errors that prevent FerroBabe from returning the requested result.
6pub enum FerroBabeError {
7 /// The byte sequence ended before the eight-byte class-file header was available.
8 #[error("class input is too short: expected at least {required} bytes, found {actual}")]
9 InputTooShort {
10 /// Minimum number of bytes required for the header.
11 required: usize,
12 /// Number of bytes supplied by the caller.
13 actual: usize,
14 },
15
16 /// The input header did not contain the Java class-file magic value.
17 #[error("input is not a Java class file: found magic 0x{found:08x}")]
18 InvalidMagic {
19 /// Four-byte value read from the input header.
20 found: u32,
21 },
22
23 /// The class-file major version is outside FerroBabe's supported range.
24 #[error(
25 "unsupported Java class-file version {major}.{minor}; FerroBabe supports 45.0 through 70.65535"
26 )]
27 UnsupportedVersion {
28 /// Unsupported class-file major version.
29 major: u16,
30 /// Class-file minor version paired with `major`.
31 minor: u16,
32 },
33
34 /// Reading from a caller-provided [`std::io::Read`] source failed.
35 #[error("class input could not be read: {source}")]
36 InputRead {
37 #[source]
38 /// Source reader error.
39 source: std::io::Error,
40 },
41
42 /// The underlying class-file decoder rejected the input.
43 #[error("class-file decoding failed: {source}")]
44 Decode {
45 #[source]
46 /// Underlying decoder error.
47 source: ClassReadError,
48 },
49
50 /// A formatter could not write to its [`std::fmt::Write`] destination.
51 #[error("formatted output could not be written")]
52 Format {
53 #[source]
54 /// Formatting destination error.
55 source: std::fmt::Error,
56 },
57
58 /// Text output was requested for a partial result that has no complete class model.
59 #[error("a partial class-file result cannot be formatted")]
60 IncompleteDisassembly,
61}