1use std::sync::Arc;
4
5use arrow::error::ArrowError;
6use nd_arrow_array::NdError;
7
8#[derive(Debug, thiserror::Error)]
10#[non_exhaustive]
11pub enum Error {
12 #[error(transparent)]
14 Nd(#[from] NdError),
15 #[error(transparent)]
17 Lance(Box<lance::Error>),
18 #[error(transparent)]
20 Arrow(#[from] ArrowError),
21 #[error("schema mismatch: {0}")]
23 SchemaMismatch(String),
24 #[error("invalid table: {0}")]
27 InvalidTable(String),
28 #[error("invalid argument: {0}")]
30 InvalidArgument(String),
31 #[error("no table at {0}")]
33 TableNotFound(String),
34 #[error("a table exists at {0}")]
36 TableExists(String),
37 #[error("commit conflict: {source}")]
40 CommitConflict {
41 retryable: bool,
43 source: Box<lance::Error>,
45 },
46 #[error("the writer failed, nothing is committed: {0}")]
48 WriterFailed(#[source] Arc<Error>),
49 #[error("a fragment write stopped: {0}")]
51 TaskFailed(#[from] tokio::task::JoinError),
52}
53
54impl From<lance::Error> for Error {
55 fn from(error: lance::Error) -> Self {
56 match error {
57 lance::Error::DatasetNotFound { path, .. } => Self::TableNotFound(path),
58 lance::Error::DatasetAlreadyExists { uri, .. } => Self::TableExists(uri),
59 lance::Error::CommitConflict { .. }
60 | lance::Error::RetryableCommitConflict { .. }
61 | lance::Error::TooMuchWriteContention { .. } => Self::CommitConflict {
62 retryable: true,
63 source: Box::new(error),
64 },
65 lance::Error::IncompatibleTransaction { .. } => Self::CommitConflict {
66 retryable: false,
67 source: Box::new(error),
68 },
69 error => Self::Lance(Box::new(error)),
70 }
71 }
72}
73
74pub type Result<T, E = Error> = std::result::Result<T, E>;