iceberg-rust: Add more variants to `ErrorKind`

Is your feature request related to a problem or challenge?

As of now, ErrorKind looks like this (doc comments removed):

pub enum ErrorKind {
    Unexpected,
    DataInvalid,
    FeatureUnsupported,
}

This is pretty bare, especially since there are whole classes of things that can go wrong with respect to the Iceberg Catalog trait. See #965 and this comment for some context for this specific repo, as well as the official REST API specification.

It would be nice if there was a dedicated error type for Catalog errors. Some simple things that could be added are variants for tables or namespaces that don’t exist, or duplicate tables or namespaces. There are many other things that can go wrong. Right now #965 just uses string messages to represent those errors, which is not ideal.

Adding dedicated error types would also mean the different implementations of the Iceberg Catalog could be more easily unified: the exact return behavior of each method would be the same among every implementation (instead of having a different error message depending on which implementation you choose).

Describe the solution you’d like

I think there are many ways to do this, some better than others. I would say that the current method manually implementing error messages, backtrace, and variants is somewhat shaky. Personally, I think that adding thiserror or snafu as a dependency for this would ease development going forward, not just the error types specified above (for the catalog) but for any other error kinds that Iceberg needs / may introduce.

Willingness to contribute

  • I can contribute to this feature independently
  • I would be willing to contribute to this feature with guidance from the Iceberg Rust community
  • I cannot contribute to this feature at this time

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 5
  • Comments: 24 (24 by maintainers)

Most upvoted comments

Perhaps we can close this issue now that we’ve reached a consensus. Additional types of errors can be discussed on a case-by-case basis.

cc @liurenjie1024 @dentiny

My philosophy is to add retry to read operation first.

I think it would be reasonable to do it first.

  • Have a dedicated retry layer, which wraps around all detailed catalogs

This will be a good idea to me. OpenDAL also follows the same pattern: https://docs.rs/opendal/0.53.1/opendal/index.html#compose-layers

I think we could introduce something like a CatalogLayer that would allow users to compose them. However, this is a significant change, so I suggest we first implement the retry logic in the REST catalog to see how it works. Then, we can design an API that makes it work with all catalogs.

Hi, @dentiny. I believe our current consensus aligns with your comments.

I think we can start by adding the following variants:

pub enum ErrorKind {
    Unexpected,
    DataInvalid,
    FeatureUnsupported,

    NamespaceNotFound,
    NamespaceExists,
    TableNotFound,
    TableExists,
}

Regarding retries, my current design is as follows: https://github.com/apache/iceberg-rust/issues/1071#issuecomment-2714693408

I think this should be managed internally by iceberg-rust. Initially, we can return a retryable or temporary field in the error for users to interpret. Later, we could consider enabling automatic retries for these errors in the REST catalog by default.

Maybe you would like to start working on this?

pub enum ErrorKind { Unexpected, DataInvalid, FeatureUnsupported,

  • NamespaceNotFound,
  • NamespaceExists,
  • TableNotFound,
  • TableExists, }

I would like to see this added as proposed

Before continuing the discussion, I would like to first explain our current error design goals. In general, error design needs to serve the following objectives:

  • The implementer does not need to do extra work.
  • The caller can know what error has occurred.
  • The caller can decide how to handle this error.
  • The caller can understand why this error occurred.

Iceberg’s error provides a clear ErrorKind, a concise summary message, and detailed context. Callers can know what happened, decide how to handle it and understand why this error occurred. It also reduce our efforts to decide while error to return while using.

This design shifts our focus from ourselves to our end users. We generally do not return errors like serde_json failure or io.EOF. Instead, we consider whether the error is meaningful to users and contributes to their error handling.

I still think it would be better if we had ErrorKind::TableNotFound, categorizing them as noun-adj. Regardless of which APIs users are calling, they would know what happened.

I propose to add:

pub enum ErrorKind {
    Unexpected,
    DataInvalid,
    FeatureUnsupported,
    
+    NamespaceNotFound,
+    NamespaceExists,
+    TableNotFound,
+    TableExists,
}

Sorry I should have been clear, I meant that there could be a dedicated Catalog error kind that could be a variant of ErrorKind. For example:

Hi, a dedicated catalog error kind doesn’t look good to me.

Let’s try write code from our users side:

let table = match ctl.load_table("test").await {
  Ok(table) => table,
  Err(err) if err.kind() == ErrorKind::TableNotExists => {
    // handle table not exists, like gerenate a user-friendly error message
  }
  Err(err) => {
    // unexpected things happend, we need to log or return bacl.
  }
} 

If we have different layers of error kind:

let table = match ctl.load_table("test").await {
  Ok(table) => table,
  Err(err) if err.kind() == ErrorKind::Catalog(CatalogErrorKind::NoSuchTable) => {
    // handle table not exists, like gerenate a user-friendly error message
  }
  Err(err) => {
    // unexpected things happend, we need to log or return bacl.
  }
} 

Users need to be aware that it’s a catalog error first. However, it’s not something they need to take action on.

Add more errors variants doesn’t serve our error handling goal too.

I think this is an interesting problem to discuss. iceberg-rust is now a multi crate project, so maybe it’s worth rethinking the design of error handling. But I think we should not only think about catalog error here, we need an extensible approach for it.

I agree with @connortsui20 's idea. The current possible enums for ErrorKind is too bare, I think a NotFound error would be pretty useful (works well as a generalized error type and additional context can be given)