use std::error::Error;
use thiserror::Error;
use crate::{Row, Value};
#[derive(Debug, Error)]
pub enum RealmFileError {
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("Invalid Realm file detected: {reason}")]
InvalidRealmFile {
reason: String,
},
#[error("Unsupported Realm feature: {reason}")]
Unsupported {
reason: String,
},
}
#[derive(Debug, Error)]
pub enum TableError {
#[error("Realm file error: {0}")]
FileError(#[from] RealmFileError),
#[error("Table not found with name '{name}'")]
TableNotFound {
name: String,
},
#[error("Column not found with name '{name}'")]
ColumnNotFound {
name: String,
},
#[error("Column '{name}' is not indexed")]
ColumnNotIndexed {
name: String,
},
}
#[derive(Debug, Error)]
pub enum ValueError {
#[error("Expected a Table value, found {found:?}")]
ExpectedTable { found: Value },
#[error("Expected a row with field '{field}', found {found:?}")]
ExpectedArrayRow {
field: &'static str,
found: Row<'static>,
},
#[error("Unexpected type: expected {expected:?}, found {found:?}")]
UnexpectedType {
expected: &'static str,
found: Value,
},
#[error("Failed to convert value in row to Vec<{element_type}>: {source}")]
VecConversionError {
element_type: &'static str,
source: Box<dyn Error>,
},
#[error(
"Missing field '{field}' when converting row into '{target_type}' (remaining fields: '{remaining_fields:?}"
)]
MissingField {
field: &'static str,
target_type: &'static str,
remaining_fields: Row<'static>,
},
}
pub type RealmResult<T> = std::result::Result<T, RealmFileError>;
pub type TableResult<T> = std::result::Result<T, TableError>;
pub type ValueResult<T> = std::result::Result<T, ValueError>;