graphannis_core/
errors.rs1use std::{
2 array::TryFromSliceError, num::TryFromIntError, str::Utf8Error, string::FromUtf8Error,
3 sync::PoisonError,
4};
5
6use thiserror::Error;
7
8use crate::types::AnnoKey;
9
10#[derive(Error, Debug)]
11#[non_exhaustive]
12pub enum GraphAnnisCoreError {
13 #[error("invalid component type {0}")]
14 InvalidComponentType(String),
15 #[error("invalid format for component description, expected ctype/layer/name, but got {0}")]
16 InvalidComponentDescriptionFormat(String),
17 #[error("could not load annotation storage from file {path}: {source}")]
18 LoadingAnnotationStorage {
19 path: String,
20 source: std::io::Error,
21 },
22 #[error("could not find implementation for graph storage with name '{0}'")]
23 UnknownGraphStorageImpl(String),
24 #[error("can't load component with empty path")]
25 EmptyComponentPath,
26 #[error("could not find annotation key ID for {0:?} when mapping to GraphML")]
27 GraphMLMissingAnnotationKey(AnnoKey),
28 #[error("could not get mutable reference for component {0}")]
29 NonExclusiveComponentReference(String),
30 #[error("component {0} is missing")]
31 MissingComponent(String),
32 #[error("component {0} was not loaded")]
33 ComponentNotLoaded(String),
34 #[error("component {0} is read-only")]
35 ReadOnlyComponent(String),
36 #[error(transparent)]
37 ModelError(#[from] ComponentTypeError),
38 #[error(transparent)]
39 BincodeSerialization(#[from] bincode::Error),
40 #[error(transparent)]
41 Io(#[from] std::io::Error),
42 #[error(transparent)]
43 PersistingTemporaryFile(#[from] tempfile::PersistError),
44 #[error(transparent)]
45 SortedStringTable(#[from] sstable::error::Status),
46 #[error(transparent)]
47 Xml(#[from] quick_xml::Error),
48 #[error(transparent)]
49 XmlAttr(#[from] quick_xml::events::attributes::AttrError),
50 #[error("Cache error: {0}")]
51 LfuCache(String),
52 #[error("File to persist graph updates is missing.")]
53 GraphUpdatePersistanceFileMissing,
54 #[error(transparent)]
55 BtreeIndex(#[from] transient_btree_index::Error),
56 #[error(transparent)]
57 IntConversion(#[from] TryFromIntError),
58 #[error(transparent)]
59 SliceConversion(#[from] TryFromSliceError),
60 #[error("Lock poisoning ({0})")]
61 LockPoisoning(String),
62 #[error(transparent)]
63 FromUtf8Error(#[from] FromUtf8Error),
64 #[error(transparent)]
65 Utf8Error(#[from] Utf8Error),
66 #[error("Too man unique items added to symbol table")]
67 SymbolTableOverflow,
68 #[error("Annotation key with ID {0} is not in symbol table")]
69 UnknownAnnoKeySymbolId(usize),
70 #[error("The choose cache size is zero, which is not allowed.")]
71 ZeroCacheSize,
72 #[error(transparent)]
73 TomlDeserializer(#[from] toml::de::Error),
74 #[error(transparent)]
75 TomlSerializer(#[from] toml::ser::Error),
76 #[error(transparent)]
77 Other(#[from] Box<dyn std::error::Error + Send + Sync>),
78}
79
80impl<T> From<PoisonError<T>> for GraphAnnisCoreError {
81 fn from(e: PoisonError<T>) -> Self {
82 Self::LockPoisoning(e.to_string())
83 }
84}
85
86#[derive(Error, Debug)]
87#[error(transparent)]
88pub struct ComponentTypeError(pub Box<dyn std::error::Error + Send + Sync>);
89
90impl From<GraphAnnisCoreError> for ComponentTypeError {
91 fn from(e: GraphAnnisCoreError) -> Self {
92 ComponentTypeError(Box::new(e))
93 }
94}
95
96pub type Result<T> = std::result::Result<T, GraphAnnisCoreError>;
97
98#[macro_export]
99macro_rules! try_as_boxed_iter {
100 ($x:expr) => {
101 match $x {
102 Ok(v) => v,
103 Err(e) => {
104 return std::boxed::Box::new(std::iter::once(Err(e.into())));
105 }
106 }
107 };
108}