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