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

refactor(connector): migrate anyhow::Error to ConnectorError newtype #15042

Merged
merged 11 commits into from
Feb 23, 2024

Conversation

BugenZhao
Copy link
Member

@BugenZhao BugenZhao commented Feb 7, 2024

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

What's changed and what's your intention?

Follow-up of #15086.

  • Migrate all functions returning anyhow::Result to ConnectorResult.
    def_anyhow_newtype! {
    pub ConnectorError,
    // Common errors
    std::io::Error => transparent,
    // Fine-grained connector errors
    AccessError => transparent,
    WireFormatError => transparent,
    ConcurrentRequestError => transparent,
    InvalidOptionError => transparent,
    SinkError => transparent,
    PbFieldNotFound => transparent,
    // TODO(error-handling): Remove implicit contexts below and specify ad-hoc context for each conversion.
    // Parsing errors
    url::ParseError => "failed to parse url",
    serde_json::Error => "failed to parse json",
    csv::Error => "failed to parse csv",
    // Connector errors
    opendal::Error => transparent, // believed to be self-explanatory
    mysql_async::Error => "MySQL error",
    tokio_postgres::Error => "Postgres error",
    apache_avro::Error => "Avro error",
    rdkafka::error::KafkaError => "Kafka error",
    pulsar::Error => "Pulsar error",
    async_nats::jetstream::consumer::StreamError => "Nats error",
    async_nats::jetstream::consumer::pull::MessagesError => "Nats error",
    async_nats::jetstream::context::CreateStreamError => "Nats error",
    async_nats::jetstream::stream::ConsumerError => "Nats error",
    icelake::Error => "Iceberg error",
    redis::RedisError => "Redis error",
    arrow_schema::ArrowError => "Arrow error",
    google_cloud_pubsub::client::google_cloud_auth::error::Error => "Google Cloud error",
    }
    • Provide default contexts for errors from external connector crates.
    • Provide ad-hoc contexts at different call sites for general error types like ParseIntError.
  • Style improvements for using context and bail to wrap and construct errors.

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.

@BugenZhao BugenZhao force-pushed the bz/connector-error-use-anyhow-newtype branch from 3b29e67 to 2dbb5fc Compare February 13, 2024 06:18
Base automatically changed from bz/connector-error-use-anyhow-newtype to main February 13, 2024 06:44
@BugenZhao BugenZhao force-pushed the bz/connector-migrate-anyhow-to-connector-error branch from 8e971ef to 126a58c Compare February 13, 2024 07:40
@BugenZhao BugenZhao changed the base branch from main to bz/connector-error-use-anyhow-newtype-retry February 13, 2024 07:40
@BugenZhao BugenZhao force-pushed the bz/connector-error-use-anyhow-newtype-retry branch from dc3fda4 to e114eee Compare February 13, 2024 08:07
@BugenZhao BugenZhao force-pushed the bz/connector-migrate-anyhow-to-connector-error branch from 69b9078 to 8a722eb Compare February 13, 2024 08:07
@BugenZhao BugenZhao marked this pull request as ready for review February 14, 2024 06:23
@BugenZhao BugenZhao force-pushed the bz/connector-migrate-anyhow-to-connector-error branch from 8a722eb to de0233c Compare February 14, 2024 06:24
Base automatically changed from bz/connector-error-use-anyhow-newtype-retry to main February 15, 2024 04:15
@buildkite buildkite bot requested a review from a team as a code owner February 15, 2024 04:15
@BugenZhao BugenZhao force-pushed the bz/connector-migrate-anyhow-to-connector-error branch 2 times, most recently from cfaeeed to 299e32d Compare February 18, 2024 08:45
Copy link
Member

@xxchan xxchan left a comment

Choose a reason for hiding this comment

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

LGTM!
At first I thought maybe it's not necessary to replace all anyhow::Error to the newtype (although this is easiest from the refactoring's point of view), but only need to change public APIs. But I quite like the added .context()s. This feels like a dynamic version of thiserror and thus I think we can use it more widely. 😄

temp_file = Some(f);
temp_file = Some(
create_credential_temp_file(&credentials)
.context("failed to create temp file for pulsar credentials")?,
Copy link
Member

Choose a reason for hiding this comment

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

😄

if payload.is_empty() {
self.value = Some("{}".into());
} else {
self.value = Some(payload);
}
let value = simd_json::to_borrowed_value(
&mut self.value.as_mut().unwrap()[self.payload_start_idx..],
)?;
)
.context("failed to parse json payload")?;
Copy link
Member

@xxchan xxchan Feb 18, 2024

Choose a reason for hiding this comment

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

What about printing the payload here in the ctx? So that we can e.g., make the error msg in #13937 nicer

Copy link
Member

Choose a reason for hiding this comment

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

Oh, it seems we can't print it without clone

@BugenZhao BugenZhao force-pushed the bz/connector-migrate-anyhow-to-connector-error branch from 299e32d to 1e6e6c2 Compare February 20, 2024 09:27
Copy link
Contributor

@chenzl25 chenzl25 left a comment

Choose a reason for hiding this comment

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

LGTM!

@BugenZhao BugenZhao force-pushed the bz/connector-migrate-anyhow-to-connector-error branch from 1e6e6c2 to fbb6b07 Compare February 22, 2024 08:55
@BugenZhao BugenZhao enabled auto-merge February 23, 2024 05:30
@BugenZhao BugenZhao force-pushed the bz/connector-migrate-anyhow-to-connector-error branch from cf13de1 to 0357432 Compare February 23, 2024 07:12
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
@BugenZhao BugenZhao force-pushed the bz/connector-migrate-anyhow-to-connector-error branch from 0357432 to ba75e21 Compare February 23, 2024 08:57
@BugenZhao BugenZhao added this pull request to the merge queue Feb 23, 2024
Copy link
Member Author

Merge activity

  • Feb 23, 4:24 AM EST: Graphite failed to merge this pull request due to This repository has GitHub's merge queue enabled, which is currently incompatible with Graphite. Try your merge again, or report a bug if you see this consistently.

Merged via the queue into main with commit b0b9fb4 Feb 23, 2024
27 of 28 checks passed
@BugenZhao BugenZhao deleted the bz/connector-migrate-anyhow-to-connector-error branch February 23, 2024 09:25
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.

3 participants