ferro_jtype/error.rs
1use thiserror::Error;
2
3/// Error returned when parsing a JVM internal class name.
4#[derive(Debug, Clone, PartialEq, Eq, Error)]
5pub enum NameError {
6 /// The provided name was empty.
7 #[error("an internal class name cannot be empty")]
8 Empty,
9 /// The provided name contains a character forbidden in an internal name.
10 #[error("invalid internal class name `{value}`")]
11 Invalid {
12 /// The invalid name supplied by the caller.
13 value: String,
14 },
15}
16
17/// Error returned when parsing a JVM type or method descriptor.
18#[derive(Debug, Clone, PartialEq, Eq, Error)]
19pub enum DescriptorError {
20 /// The descriptor ended before a complete value could be parsed.
21 #[error("descriptor ended unexpectedly at byte {offset}")]
22 UnexpectedEnd {
23 /// Zero-based byte offset where input ended.
24 offset: usize,
25 },
26 /// A required descriptor character was not found at the given byte offset.
27 #[error("expected `{expected}` at byte {offset}")]
28 Expected {
29 /// Character required by the descriptor grammar.
30 expected: char,
31 /// Zero-based byte offset where the character was required.
32 offset: usize,
33 },
34 /// An unrecognized descriptor tag was found at the given byte offset.
35 #[error("invalid descriptor tag `{tag}` at byte {offset}")]
36 InvalidTag {
37 /// Unrecognized descriptor tag.
38 tag: char,
39 /// Zero-based byte offset of the tag.
40 offset: usize,
41 },
42 /// An array descriptor exceeded the JVM's 255-dimension limit.
43 #[error("array descriptor exceeds the JVM limit of 255 dimensions")]
44 TooManyArrayDimensions,
45 /// Extra data followed an otherwise complete descriptor.
46 #[error("descriptor contains trailing input at byte {offset}")]
47 TrailingInput {
48 /// Zero-based byte offset of the first trailing byte.
49 offset: usize,
50 },
51 /// The descriptor contained an invalid internal class name.
52 #[error(transparent)]
53 InvalidClassName(#[from] NameError),
54}
55
56/// Error returned when a class file cannot be analyzed.
57#[derive(Debug, Error)]
58pub enum Error {
59 /// A caller-supplied reference archive or one of its class entries could not be read.
60 #[error("failed to read reference library entry `{entry}`: {source}")]
61 ReferenceLibrary {
62 /// Archive path or entry name that failed.
63 entry: String,
64 /// Underlying archive, I/O, or class-header error.
65 #[source]
66 source: Box<dyn std::error::Error + Send + Sync>,
67 },
68 /// The supplied bytes could not be decoded as a Java class file.
69 #[error("failed to decode class file: {0}")]
70 Decode(#[from] ferro_babe::FerroBabeError),
71 /// Recovery produced an incomplete class representation.
72 #[error("class file recovery did not produce a complete class")]
73 IncompleteClass,
74 /// More than one batch input declared the same internal class name.
75 #[error("duplicate class input for `{class_name}`")]
76 DuplicateClass {
77 /// The duplicate JVM internal class name.
78 class_name: crate::ClassName,
79 },
80 /// The class-file structure could not be traversed safely before inference.
81 #[error("invalid class-file structure: {message}")]
82 InvalidClassFile {
83 /// Explanation of the malformed structure.
84 message: String,
85 },
86 /// A descriptor embedded in the class file was invalid.
87 #[error(transparent)]
88 Descriptor(#[from] DescriptorError),
89 /// An [`crate::InferenceConfig`] contained an invalid limit.
90 #[error("invalid inference configuration: {message}")]
91 InvalidConfiguration {
92 /// Explanation of the rejected configuration value.
93 message: String,
94 },
95 /// Strict mode rejected a warning or error diagnostic.
96 #[error("strict analysis rejected a diagnostic: {message}")]
97 StrictAnalysis {
98 /// Message of the diagnostic rejected by strict mode.
99 message: String,
100 },
101}