Skip to content

Commit 95ccf92

Browse files
authored
feat(core/catalog): Add more error kinds (#1265)
1 parent 947fbc1 commit 95ccf92

File tree

4 files changed

+39
-22
lines changed

4 files changed

+39
-22
lines changed

crates/catalog/glue/src/catalog.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ impl Catalog for GlueCatalog {
452452

453453
match glue_table_output.table() {
454454
None => Err(Error::new(
455-
ErrorKind::Unexpected,
455+
ErrorKind::TableNotFound,
456456
format!(
457457
"Table object for database: {} and table: {} does not exist",
458458
db_name, table_name
@@ -566,7 +566,7 @@ impl Catalog for GlueCatalog {
566566

567567
match glue_table_output.table() {
568568
None => Err(Error::new(
569-
ErrorKind::Unexpected,
569+
ErrorKind::TableNotFound,
570570
format!(
571571
"'Table' object for database: {} and table: {} does not exist",
572572
src_db_name, src_table_name

crates/catalog/memory/src/catalog.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ mod tests {
598598
.unwrap_err()
599599
.to_string(),
600600
format!(
601-
"Unexpected => Cannot create namespace {:?}. Namespace already exists.",
601+
"NamespaceAlreadyExists => Cannot create namespace {:?}. Namespace already exists.",
602602
&namespace_ident
603603
)
604604
);
@@ -667,7 +667,7 @@ mod tests {
667667
.unwrap_err()
668668
.to_string(),
669669
format!(
670-
"Unexpected => No such namespace: {:?}",
670+
"NamespaceNotFound => No such namespace: {:?}",
671671
NamespaceIdent::new("a".into())
672672
)
673673
);
@@ -692,7 +692,7 @@ mod tests {
692692
.unwrap_err()
693693
.to_string(),
694694
format!(
695-
"Unexpected => No such namespace: {:?}",
695+
"NamespaceNotFound => No such namespace: {:?}",
696696
NamespaceIdent::from_strs(vec!["a", "b"]).unwrap()
697697
)
698698
);
@@ -773,7 +773,7 @@ mod tests {
773773
.unwrap_err()
774774
.to_string(),
775775
format!(
776-
"Unexpected => No such namespace: {:?}",
776+
"NamespaceNotFound => No such namespace: {:?}",
777777
non_existent_namespace_ident
778778
)
779779
)
@@ -860,7 +860,7 @@ mod tests {
860860
.unwrap_err()
861861
.to_string(),
862862
format!(
863-
"Unexpected => No such namespace: {:?}",
863+
"NamespaceNotFound => No such namespace: {:?}",
864864
non_existent_namespace_ident
865865
)
866866
)
@@ -937,7 +937,7 @@ mod tests {
937937
.unwrap_err()
938938
.to_string(),
939939
format!(
940-
"Unexpected => No such namespace: {:?}",
940+
"NamespaceNotFound => No such namespace: {:?}",
941941
non_existent_namespace_ident
942942
)
943943
)
@@ -957,7 +957,7 @@ mod tests {
957957
.unwrap_err()
958958
.to_string(),
959959
format!(
960-
"Unexpected => No such namespace: {:?}",
960+
"NamespaceNotFound => No such namespace: {:?}",
961961
non_existent_namespace_ident
962962
)
963963
)
@@ -1257,7 +1257,7 @@ mod tests {
12571257
.unwrap_err()
12581258
.to_string(),
12591259
format!(
1260-
"Unexpected => Cannot create table {:?}. Table already exists.",
1260+
"TableAlreadyExists => Cannot create table {:?}. Table already exists.",
12611261
&table_ident
12621262
)
12631263
);
@@ -1359,7 +1359,7 @@ mod tests {
13591359
.unwrap_err()
13601360
.to_string(),
13611361
format!(
1362-
"Unexpected => No such namespace: {:?}",
1362+
"NamespaceNotFound => No such namespace: {:?}",
13631363
non_existent_namespace_ident
13641364
),
13651365
);
@@ -1409,7 +1409,7 @@ mod tests {
14091409
.unwrap_err()
14101410
.to_string(),
14111411
format!(
1412-
"Unexpected => No such namespace: {:?}",
1412+
"NamespaceNotFound => No such namespace: {:?}",
14131413
non_existent_namespace_ident
14141414
),
14151415
);
@@ -1430,7 +1430,7 @@ mod tests {
14301430
.unwrap_err()
14311431
.to_string(),
14321432
format!(
1433-
"Unexpected => No such table: {:?}",
1433+
"TableNotFound => No such table: {:?}",
14341434
non_existent_table_ident
14351435
),
14361436
);
@@ -1494,7 +1494,7 @@ mod tests {
14941494
.unwrap_err()
14951495
.to_string(),
14961496
format!(
1497-
"Unexpected => No such namespace: {:?}",
1497+
"NamespaceNotFound => No such namespace: {:?}",
14981498
non_existent_namespace_ident
14991499
),
15001500
);
@@ -1609,7 +1609,7 @@ mod tests {
16091609
.unwrap_err()
16101610
.to_string(),
16111611
format!(
1612-
"Unexpected => No such namespace: {:?}",
1612+
"NamespaceNotFound => No such namespace: {:?}",
16131613
non_existent_src_namespace_ident
16141614
),
16151615
);
@@ -1633,7 +1633,7 @@ mod tests {
16331633
.unwrap_err()
16341634
.to_string(),
16351635
format!(
1636-
"Unexpected => No such namespace: {:?}",
1636+
"NamespaceNotFound => No such namespace: {:?}",
16371637
non_existent_dst_namespace_ident
16381638
),
16391639
);
@@ -1653,7 +1653,7 @@ mod tests {
16531653
.await
16541654
.unwrap_err()
16551655
.to_string(),
1656-
format!("Unexpected => No such table: {:?}", src_table_ident),
1656+
format!("TableNotFound => No such table: {:?}", src_table_ident),
16571657
);
16581658
}
16591659

@@ -1673,7 +1673,7 @@ mod tests {
16731673
.unwrap_err()
16741674
.to_string(),
16751675
format!(
1676-
"Unexpected => Cannot create table {:? }. Table already exists.",
1676+
"TableAlreadyExists => Cannot create table {:? }. Table already exists.",
16771677
&dst_table_ident
16781678
),
16791679
);

crates/catalog/memory/src/namespace_state.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,21 @@ pub(crate) struct NamespaceState {
3333

3434
fn no_such_namespace_err<T>(namespace_ident: &NamespaceIdent) -> Result<T> {
3535
Err(Error::new(
36-
ErrorKind::Unexpected,
36+
ErrorKind::NamespaceNotFound,
3737
format!("No such namespace: {:?}", namespace_ident),
3838
))
3939
}
4040

4141
fn no_such_table_err<T>(table_ident: &TableIdent) -> Result<T> {
4242
Err(Error::new(
43-
ErrorKind::Unexpected,
43+
ErrorKind::TableNotFound,
4444
format!("No such table: {:?}", table_ident),
4545
))
4646
}
4747

4848
fn namespace_already_exists_err<T>(namespace_ident: &NamespaceIdent) -> Result<T> {
4949
Err(Error::new(
50-
ErrorKind::Unexpected,
50+
ErrorKind::NamespaceAlreadyExists,
5151
format!(
5252
"Cannot create namespace {:?}. Namespace already exists.",
5353
namespace_ident
@@ -57,7 +57,7 @@ fn namespace_already_exists_err<T>(namespace_ident: &NamespaceIdent) -> Result<T
5757

5858
fn table_already_exists_err<T>(table_ident: &TableIdent) -> Result<T> {
5959
Err(Error::new(
60-
ErrorKind::Unexpected,
60+
ErrorKind::TableAlreadyExists,
6161
format!(
6262
"Cannot create table {:?}. Table already exists.",
6363
table_ident

crates/iceberg/src/error.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ pub enum ErrorKind {
4040
///
4141
/// The table could be invalid or corrupted.
4242
DataInvalid,
43+
44+
/// Iceberg namespace already exists at creation.
45+
NamespaceAlreadyExists,
46+
47+
/// Iceberg table already exists at creation.
48+
TableAlreadyExists,
49+
50+
/// Iceberg namespace already exists at creation.
51+
NamespaceNotFound,
52+
53+
/// Iceberg table already exists at creation.
54+
TableNotFound,
55+
4356
/// Iceberg feature is not supported.
4457
///
4558
/// This error is returned when given iceberg feature is not supported.
@@ -59,6 +72,10 @@ impl From<ErrorKind> for &'static str {
5972
ErrorKind::Unexpected => "Unexpected",
6073
ErrorKind::DataInvalid => "DataInvalid",
6174
ErrorKind::FeatureUnsupported => "FeatureUnsupported",
75+
ErrorKind::TableAlreadyExists => "TableAlreadyExists",
76+
ErrorKind::TableNotFound => "TableNotFound",
77+
ErrorKind::NamespaceAlreadyExists => "NamespaceAlreadyExists",
78+
ErrorKind::NamespaceNotFound => "NamespaceNotFound",
6279
}
6380
}
6481
}

0 commit comments

Comments
 (0)