1use crate::architecture::ArchitectureDef;
2use thiserror::Error;
3
4#[derive(Debug, Error)]
5pub enum Error {
6 #[error("{name} backend: {source}")]
7 ImporterBackend { name: &'static str, source: Box<dyn std::error::Error + Send + Sync + 'static> },
8 #[error(transparent)]
9 CannotCreateTempDir(std::io::Error),
10 #[error(transparent)]
11 CannotReadFile(std::io::Error),
12 #[error(transparent)]
13 CannotWriteFile(std::io::Error),
14 #[error(transparent)]
15 Deserialisation(flatbuffers::InvalidFlatbuffer),
16 #[error("field `{0}` to deserialise is missing")]
17 DeserialiseField(&'static str),
18 #[error("export path `{}` for serialised database already exists", _0.display())]
19 ExportPathExists(std::path::PathBuf),
20 #[error("export of serialised database failed: {0}")]
21 ExportViaCopy(fs_extra::error::Error),
22 #[error("function at {0:#x} has no corresponding segment")]
23 NoFunctionSegment(u64),
24 #[error("block at {0:#x} has no corresponding segment")]
25 NoBlockSegment(u64),
26 #[error("no importer backends available")]
27 NoBackendsAvailable,
28 #[error("no URL specified for database import")]
29 NoImportUrl,
30 #[error("file not found at `{}`", _0.display())]
31 FileNotFound(std::path::PathBuf),
32 #[error("invalid local import URL `{0}`")]
33 InvalidLocalImportUrl(url::Url),
34 #[error("could not lift instruction at {address:#x}: {source}")]
35 Lifting { address: u64, source: fugue_ir::error::Error },
36 #[error(transparent)]
37 Translator(fugue_ir::error::Error),
38 #[error("unsupported architecture: {0}")]
39 UnsupportedArchitecture(ArchitectureDef),
40 #[error("unsupported format `{0}`")]
41 UnsupportedFormat(String),
42}
43
44impl Error {
45 pub fn importer_error<E>(name: &'static str, e: E) -> Self
46 where E: std::error::Error + Send + Sync + 'static {
47 Self::ImporterBackend { name, source: Box::new(e) }
48 }
49}