Skip to main content

type_crawler/
error.rs

1use clang::SourceError;
2use snafu::Snafu;
3
4use crate::ExtendTypesError;
5
6#[derive(Debug, Snafu)]
7#[snafu(visibility(pub(crate)))]
8pub enum TypeCrawlerError {
9    #[snafu(display("Failed to initialize clang: {message}"))]
10    ClangInit { message: String },
11}
12
13#[derive(Debug, Snafu)]
14#[snafu(visibility(pub(crate)))]
15pub enum AddIncludePathError {
16    #[snafu(display("Path does not exist: {path}"))]
17    DoesNotExist { path: String },
18    #[snafu(display("Path is not a directory: {path}"))]
19    NotADirectory { path: String },
20}
21
22#[derive(Debug, Snafu)]
23#[snafu(visibility(pub(crate)))]
24pub enum ParseError {
25    #[snafu(display("File not found: {name}"))]
26    FileNotFound { name: String },
27    #[snafu(display("Failed to read file: {path}"))]
28    ReadError { path: String },
29    #[snafu(transparent)]
30    ParseError { source: SourceError },
31    #[snafu(display("Invalid AST: {message}"))]
32    InvalidAst { message: String },
33    #[snafu(display("Unsupported type: {message}"))]
34    UnsupportedType { message: String },
35    #[snafu(display("Unsupported entity in {at}: {message}"))]
36    UnsupportedEntity { at: String, message: String },
37    #[snafu(display("Failed to get field offset of {field_name} in {struct_name}: {error}"))]
38    Offsetof { field_name: String, struct_name: String, error: clang::OffsetofError },
39    #[snafu(display("Failed to get size of type {type_name}: {error}"))]
40    Sizeof { type_name: String, error: clang::SizeofError },
41    #[snafu(display("Failed to get alignment of type {type_name}: {error}"))]
42    Alignof { type_name: String, error: clang::AlignofError },
43    #[snafu(display("Invalid fields in {struct_name}: {field_names:?}"))]
44    InvalidFields { field_names: Vec<String>, struct_name: String },
45    #[snafu(transparent)]
46    ExtendTypesError { source: ExtendTypesError },
47}