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
//! 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 IndexerError {
    // 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),
}

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