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 XmlEncoding(#[from] quick_xml::encoding::EncodingError),
50 #[error(transparent)]
51 XmlAttr(#[from] quick_xml::events::attributes::AttrError),
52 #[error("Cache error: {0}")]
53 LfuCache(String),
54 #[error("File to persist graph updates is missing.")]
55 GraphUpdatePersistanceFileMissing,
56 #[error(transparent)]
57 BtreeIndex(#[from] transient_btree_index::Error),
58 #[error(transparent)]
59 IntConversion(#[from] TryFromIntError),
60 #[error(transparent)]
61 SliceConversion(#[from] TryFromSliceError),
62 #[error("Lock poisoning ({0})")]
63 LockPoisoning(String),
64 #[error(transparent)]
65 FromUtf8Error(#[from] FromUtf8Error),
66 #[error(transparent)]
67 Utf8Error(#[from] Utf8Error),
68 #[error("Too man unique items added to symbol table")]
69 SymbolTableOverflow,
70 #[error("Annotation key with ID {0} is not in symbol table")]
71 UnknownAnnoKeySymbolId(usize),
72 #[error("The choose cache size is zero, which is not allowed.")]
73 ZeroCacheSize,
74 #[error(transparent)]
75 TomlDeserializer(#[from] toml::de::Error),
76 #[error(transparent)]
77 TomlSerializer(#[from] toml::ser::Error),
78 #[error(transparent)]
79 Other(#[from] Box<dyn std::error::Error + Send + Sync>),
80}
81
82impl<T> From<PoisonError<T>> for GraphAnnisCoreError {
83 fn from(e: PoisonError<T>) -> Self {
84 Self::LockPoisoning(e.to_string())
85 }
86}
87
88#[derive(Error, Debug)]
89#[error(transparent)]
90pub struct ComponentTypeError(pub Box<dyn std::error::Error + Send + Sync>);
91
92impl From<GraphAnnisCoreError> for ComponentTypeError {
93 fn from(e: GraphAnnisCoreError) -> Self {
94 ComponentTypeError(Box::new(e))
95 }
96}
97
98pub type Result<T> = std::result::Result<T, GraphAnnisCoreError>;
99
100#[macro_export]
101macro_rules! try_as_boxed_iter {
102 ($x:expr) => {
103 match $x {
104 Ok(v) => v,
105 Err(e) => {
106 return std::boxed::Box::new(std::iter::once(Err(e.into())));
107 }
108 }
109 };
110}