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
//! Contains errors raised during the indexing process

use crate::record::decoder::RecordDecoderError;

use ciborium::{de::Error as DecodeError, ser::Error as EncodeError};
use ore_rs::OREError;
use thiserror::Error;

/// An error that occurs when creating or loading a RecordIndexer from CBOR.
#[derive(Error, Debug)]
pub enum LoadIndexerError {
    #[error("Failed to decode: {0}")]
    DecodeError(#[from] DecodeError<std::io::Error>),
    #[error("{0}")]
    Other(String),
}

#[derive(Error, Debug)]
pub enum RecordIndexingError {
    // At the moment the ORE errors don't have any info
    // So if they happen just return this ORE tag
    #[error("An unknown ORE error occurred")]
    ORE,
    #[error("An error occurred when decoding record: {0}")]
    DecodeError(#[from] RecordDecoderError),
    #[error("An error occurred when encoding result: {0}")]
    EncodeError(#[from] EncodeError<std::io::Error>),
    #[error("{0}")]
    InvalidRecordError(String),
}

#[derive(Error, Debug, PartialEq)]
pub enum QueryIndexingError {
    // At the moment the ORE errors don't have any info
    // So if they happen just return this ORE tag
    #[error("An unknown ORE error occurred")]
    ORE,
    #[error("Can't perform query of type '{query_name}' against mapping of type '{mapping_name}'")]
    InvalidQueryMappingPair {
        query_name: &'static str,
        mapping_name: &'static str,
    },
    #[error("Index name '{0}' does not exist")]
    InvalidIndexName(String),
    #[error("Can't use a string to query range index")]
    RangeQueryStringError,
}

impl From<OREError> for QueryIndexingError {
    fn from(_val: OREError) -> Self {
        Self::ORE
    }
}

impl From<OREError> for RecordIndexingError {
    fn from(_val: OREError) -> Self {
        Self::ORE
    }
}

#[derive(Error, Debug)]
pub enum CollectionSchemaError {
    #[error("Index key is not valid")]
    InvalidIndexKey,
}