This is an automated email from the ASF dual-hosted git repository.
liurenjie1024 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-rust.git
The following commit(s) were added to refs/heads/main by this push:
new 95ccf92a feat(core/catalog): Add more error kinds (#1265)
95ccf92a is described below
commit 95ccf92a1d9af5f424f632efb567af5371763306
Author: dentiny <[email protected]>
AuthorDate: Sun Apr 27 06:36:15 2025 -0700
feat(core/catalog): Add more error kinds (#1265)
---
crates/catalog/glue/src/catalog.rs | 4 ++--
crates/catalog/memory/src/catalog.rs | 32 ++++++++++++++--------------
crates/catalog/memory/src/namespace_state.rs | 8 +++----
crates/iceberg/src/error.rs | 17 +++++++++++++++
4 files changed, 39 insertions(+), 22 deletions(-)
diff --git a/crates/catalog/glue/src/catalog.rs
b/crates/catalog/glue/src/catalog.rs
index 6e7cdd69..0b7648d9 100644
--- a/crates/catalog/glue/src/catalog.rs
+++ b/crates/catalog/glue/src/catalog.rs
@@ -452,7 +452,7 @@ impl Catalog for GlueCatalog {
match glue_table_output.table() {
None => Err(Error::new(
- ErrorKind::Unexpected,
+ ErrorKind::TableNotFound,
format!(
"Table object for database: {} and table: {} does not
exist",
db_name, table_name
@@ -566,7 +566,7 @@ impl Catalog for GlueCatalog {
match glue_table_output.table() {
None => Err(Error::new(
- ErrorKind::Unexpected,
+ ErrorKind::TableNotFound,
format!(
"'Table' object for database: {} and table: {} does not
exist",
src_db_name, src_table_name
diff --git a/crates/catalog/memory/src/catalog.rs
b/crates/catalog/memory/src/catalog.rs
index 99563011..cf4ad721 100644
--- a/crates/catalog/memory/src/catalog.rs
+++ b/crates/catalog/memory/src/catalog.rs
@@ -598,7 +598,7 @@ mod tests {
.unwrap_err()
.to_string(),
format!(
- "Unexpected => Cannot create namespace {:?}. Namespace already
exists.",
+ "NamespaceAlreadyExists => Cannot create namespace {:?}.
Namespace already exists.",
&namespace_ident
)
);
@@ -667,7 +667,7 @@ mod tests {
.unwrap_err()
.to_string(),
format!(
- "Unexpected => No such namespace: {:?}",
+ "NamespaceNotFound => No such namespace: {:?}",
NamespaceIdent::new("a".into())
)
);
@@ -692,7 +692,7 @@ mod tests {
.unwrap_err()
.to_string(),
format!(
- "Unexpected => No such namespace: {:?}",
+ "NamespaceNotFound => No such namespace: {:?}",
NamespaceIdent::from_strs(vec!["a", "b"]).unwrap()
)
);
@@ -773,7 +773,7 @@ mod tests {
.unwrap_err()
.to_string(),
format!(
- "Unexpected => No such namespace: {:?}",
+ "NamespaceNotFound => No such namespace: {:?}",
non_existent_namespace_ident
)
)
@@ -860,7 +860,7 @@ mod tests {
.unwrap_err()
.to_string(),
format!(
- "Unexpected => No such namespace: {:?}",
+ "NamespaceNotFound => No such namespace: {:?}",
non_existent_namespace_ident
)
)
@@ -937,7 +937,7 @@ mod tests {
.unwrap_err()
.to_string(),
format!(
- "Unexpected => No such namespace: {:?}",
+ "NamespaceNotFound => No such namespace: {:?}",
non_existent_namespace_ident
)
)
@@ -957,7 +957,7 @@ mod tests {
.unwrap_err()
.to_string(),
format!(
- "Unexpected => No such namespace: {:?}",
+ "NamespaceNotFound => No such namespace: {:?}",
non_existent_namespace_ident
)
)
@@ -1257,7 +1257,7 @@ mod tests {
.unwrap_err()
.to_string(),
format!(
- "Unexpected => Cannot create table {:?}. Table already
exists.",
+ "TableAlreadyExists => Cannot create table {:?}. Table already
exists.",
&table_ident
)
);
@@ -1359,7 +1359,7 @@ mod tests {
.unwrap_err()
.to_string(),
format!(
- "Unexpected => No such namespace: {:?}",
+ "NamespaceNotFound => No such namespace: {:?}",
non_existent_namespace_ident
),
);
@@ -1409,7 +1409,7 @@ mod tests {
.unwrap_err()
.to_string(),
format!(
- "Unexpected => No such namespace: {:?}",
+ "NamespaceNotFound => No such namespace: {:?}",
non_existent_namespace_ident
),
);
@@ -1430,7 +1430,7 @@ mod tests {
.unwrap_err()
.to_string(),
format!(
- "Unexpected => No such table: {:?}",
+ "TableNotFound => No such table: {:?}",
non_existent_table_ident
),
);
@@ -1494,7 +1494,7 @@ mod tests {
.unwrap_err()
.to_string(),
format!(
- "Unexpected => No such namespace: {:?}",
+ "NamespaceNotFound => No such namespace: {:?}",
non_existent_namespace_ident
),
);
@@ -1609,7 +1609,7 @@ mod tests {
.unwrap_err()
.to_string(),
format!(
- "Unexpected => No such namespace: {:?}",
+ "NamespaceNotFound => No such namespace: {:?}",
non_existent_src_namespace_ident
),
);
@@ -1633,7 +1633,7 @@ mod tests {
.unwrap_err()
.to_string(),
format!(
- "Unexpected => No such namespace: {:?}",
+ "NamespaceNotFound => No such namespace: {:?}",
non_existent_dst_namespace_ident
),
);
@@ -1653,7 +1653,7 @@ mod tests {
.await
.unwrap_err()
.to_string(),
- format!("Unexpected => No such table: {:?}", src_table_ident),
+ format!("TableNotFound => No such table: {:?}", src_table_ident),
);
}
@@ -1673,7 +1673,7 @@ mod tests {
.unwrap_err()
.to_string(),
format!(
- "Unexpected => Cannot create table {:? }. Table already
exists.",
+ "TableAlreadyExists => Cannot create table {:? }. Table
already exists.",
&dst_table_ident
),
);
diff --git a/crates/catalog/memory/src/namespace_state.rs
b/crates/catalog/memory/src/namespace_state.rs
index 653487f3..de153220 100644
--- a/crates/catalog/memory/src/namespace_state.rs
+++ b/crates/catalog/memory/src/namespace_state.rs
@@ -33,21 +33,21 @@ pub(crate) struct NamespaceState {
fn no_such_namespace_err<T>(namespace_ident: &NamespaceIdent) -> Result<T> {
Err(Error::new(
- ErrorKind::Unexpected,
+ ErrorKind::NamespaceNotFound,
format!("No such namespace: {:?}", namespace_ident),
))
}
fn no_such_table_err<T>(table_ident: &TableIdent) -> Result<T> {
Err(Error::new(
- ErrorKind::Unexpected,
+ ErrorKind::TableNotFound,
format!("No such table: {:?}", table_ident),
))
}
fn namespace_already_exists_err<T>(namespace_ident: &NamespaceIdent) ->
Result<T> {
Err(Error::new(
- ErrorKind::Unexpected,
+ ErrorKind::NamespaceAlreadyExists,
format!(
"Cannot create namespace {:?}. Namespace already exists.",
namespace_ident
@@ -57,7 +57,7 @@ fn namespace_already_exists_err<T>(namespace_ident:
&NamespaceIdent) -> Result<T
fn table_already_exists_err<T>(table_ident: &TableIdent) -> Result<T> {
Err(Error::new(
- ErrorKind::Unexpected,
+ ErrorKind::TableAlreadyExists,
format!(
"Cannot create table {:?}. Table already exists.",
table_ident
diff --git a/crates/iceberg/src/error.rs b/crates/iceberg/src/error.rs
index e539bf06..1eef1bcc 100644
--- a/crates/iceberg/src/error.rs
+++ b/crates/iceberg/src/error.rs
@@ -40,6 +40,19 @@ pub enum ErrorKind {
///
/// The table could be invalid or corrupted.
DataInvalid,
+
+ /// Iceberg namespace already exists at creation.
+ NamespaceAlreadyExists,
+
+ /// Iceberg table already exists at creation.
+ TableAlreadyExists,
+
+ /// Iceberg namespace already exists at creation.
+ NamespaceNotFound,
+
+ /// Iceberg table already exists at creation.
+ TableNotFound,
+
/// Iceberg feature is not supported.
///
/// This error is returned when given iceberg feature is not supported.
@@ -59,6 +72,10 @@ impl From<ErrorKind> for &'static str {
ErrorKind::Unexpected => "Unexpected",
ErrorKind::DataInvalid => "DataInvalid",
ErrorKind::FeatureUnsupported => "FeatureUnsupported",
+ ErrorKind::TableAlreadyExists => "TableAlreadyExists",
+ ErrorKind::TableNotFound => "TableNotFound",
+ ErrorKind::NamespaceAlreadyExists => "NamespaceAlreadyExists",
+ ErrorKind::NamespaceNotFound => "NamespaceNotFound",
}
}
}