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 PineconeError: use thiserror/anyhow, ensure we support Send + Sync #56

Merged
merged 1 commit into from
Sep 4, 2024

Conversation

austin-denoble
Copy link
Contributor

@austin-denoble austin-denoble commented Sep 3, 2024

Problem

Currently, PineconeError contains a lot of boilerplate for implementing std::error::Error. @haruska suggested we could maybe simplify some of the boilerplate using the thiserror and anyhow crates.

Additionally, there was an enhancement filed (#54) to implement Send + Sync for PineconeError as currently we're unable to use PineconeError in a multithreaded context.

Solution

Refactor PineconeError to use thiserror and anyhow to reduce some of our boilerplate for the custom error enum, make sure we can safely use PineconeError with Send and Sync, add unit test for this

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Infrastructure change (CI configs, etc)
  • Non-code change (docs, etc)
  • None of the above: (explain here)

Test Plan

New unit test added to verify that PineoneError has properly implemented the Send and Sync traits.

cargo test -> validate CI passes as expected


…our boilerplate for the custom error enum, make sure we can safely use PineconeError with Send and Sync, add unit test for this
@austin-denoble austin-denoble changed the title Refactor PineconeError: use thiserror/anyhow & ensure we support Send + Sync Refactor PineconeError: use thiserror/anyhow, ensure we support Send + Sync Sep 3, 2024
@@ -210,123 +239,6 @@ fn parse_forbidden_error(source: WrappedResponseContent, message: String) -> Pin
}
}

impl std::fmt::Display for PineconeError {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These Display implementations are basically all up in the #[error("message")] annotations above each error in the enum due to deriving thiserror::Error.

}
}

impl std::error::Error for PineconeError {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Handled with deriving thiserror::Error.

Comment on lines +277 to +282
fn assert_send_sync<T: Send + Sync>() {}

#[tokio::test]
async fn test_pinecone_error_is_send_sync() {
assert_send_sync::<PineconeError>();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Testing to ensure we're properly implementing Send + Sync on the custom error type.

@austin-denoble austin-denoble marked this pull request as ready for review September 3, 2024 20:28
ConnectionError {
/// inner: Error object for connection error.
source: Box<dyn std::error::Error>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue with no adhering to Send + Sync was due to this inner error type.

Copy link

@haruska haruska left a comment

Choose a reason for hiding this comment

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

Good improvement!

Copy link
Contributor

@ssmith-pc ssmith-pc left a comment

Choose a reason for hiding this comment

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

Love it

@austin-denoble austin-denoble merged commit fc241fe into main Sep 4, 2024
2 checks passed
@austin-denoble austin-denoble deleted the adenoble/pinecone-error-send-sync branch September 4, 2024 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants