Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(batch): ensure user-facing context is always present for external system errors #18982

Merged
merged 6 commits into from
Oct 18, 2024

Conversation

kwannoel
Copy link
Contributor

@kwannoel kwannoel commented Oct 17, 2024

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

Closes #18860

This PR adds a new macro def_anyhow_variant. The semantics of it is to construct a newtype error (same as def_anyhow_newtype), and also implement the From trait for each variant of the newtype to the parent error, which the newtype is a variant of.

Using this, we create the BatchExternalSystemError, and also allow types which are variants of it to be cast into BatchError, which ExternalSystemError is a variant of.

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added test labels as necessary. See details.
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

Release note

If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.

@graphite-app graphite-app bot requested a review from a team October 17, 2024 13:55
@kwannoel kwannoel changed the title feat(batch): add ExternalSystemError variant feat(batch): add ExternalSystemError variant to enforce context Oct 17, 2024
@kwannoel kwannoel changed the title feat(batch): add ExternalSystemError variant to enforce context feat(batch): ensure user-facing context is always present for external system errors Oct 17, 2024
src/batch/src/error.rs Outdated Show resolved Hide resolved
src/error/src/anyhow.rs Outdated Show resolved Hide resolved
@kwannoel
Copy link
Contributor Author

Macro expansion

#[derive(::thiserror::Error, ::std::fmt::Debug)]
#[error(transparent)]
pub struct BatchExternalSystemError
(#[from]
 #[backtrace]   ::anyhow::Error);
impl BatchExternalSystemError
{
    ///   Unwrap the newtype to get the inner  [` anyhow::Error `] . 
    pub fn into_inner(self) -> ::anyhow::Error {
        self.0
    }

    ///   Get the type name of the inner error. 
    pub fn variant_name(&self) -> &'static str {
        if self.0.downcast_ref::<tokio_postgres::Error>().is_some() {
            return "tokio_postgres::Error";
        }
        if self.0.downcast_ref::<iceberg::Error>().is_some() {
            return "iceberg::Error";
        }
        if self.0.downcast_ref::<ParquetError>().is_some() {
            return "ParquetError";
        }
        return "connector_error";
    }
}
impl From<tokio_postgres::Error> for BatchExternalSystemError
{
    fn from(error: tokio_postgres::Error) -> Self {
        Self(::anyhow::Error::new(error).context("Postgres error"))
    }
}
impl From<iceberg::Error> for BatchExternalSystemError
{
    fn from(error: iceberg::Error) -> Self {
        Self(::anyhow::Error::new(error).context("Iceberg error"))
    }
}
impl From<ParquetError> for BatchExternalSystemError
{
    fn from(error: ParquetError) -> Self {
        Self(::anyhow::Error::new(error).context("Parquet error"
        ))
    }
}
impl From<tokio_postgres::Error> for BatchError {
    fn from(error: tokio_postgres::Error) -> Self {
        BatchError::ExternalSystemError(BatchExternalSystemError::from(error))
    }
}
impl From<iceberg::Error> for BatchError {
    fn from(error: iceberg::Error) -> Self {
        BatchError::ExternalSystemError(BatchExternalSystemError::from(error))
    }
}
impl From<ParquetError> for BatchError {
    fn from(error: ParquetError) -> Self {
        BatchError::ExternalSystemError(BatchExternalSystemError::from(error))
    }
}

@kwannoel kwannoel requested a review from BugenZhao October 18, 2024 07:07
Copy link
Member

@BugenZhao BugenZhao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kwannoel kwannoel added this pull request to the merge queue Oct 18, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 18, 2024
@kwannoel kwannoel added this pull request to the merge queue Oct 18, 2024
Merged via the queue into main with commit 3b16130 Oct 18, 2024
33 of 34 checks passed
@kwannoel kwannoel deleted the kwannoel/external-system-error branch October 18, 2024 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a ExternalSystemError in BatchError to force explicit handling of external system errors
2 participants