-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
…our boilerplate for the custom error enum, make sure we can safely use PineconeError with Send and Sync, add unit test for this
PineconeError
: use thiserror
/anyhow
& ensure we support Send + Sync
PineconeError
: use thiserror
/anyhow
, ensure we support Send + Sync
@@ -210,123 +239,6 @@ fn parse_forbidden_error(source: WrappedResponseContent, message: String) -> Pin | |||
} | |||
} | |||
|
|||
impl std::fmt::Display for PineconeError { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
.
fn assert_send_sync<T: Send + Sync>() {} | ||
|
||
#[tokio::test] | ||
async fn test_pinecone_error_is_send_sync() { | ||
assert_send_sync::<PineconeError>(); | ||
} |
There was a problem hiding this comment.
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.
ConnectionError { | ||
/// inner: Error object for connection error. | ||
source: Box<dyn std::error::Error>, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good improvement!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it
Problem
Currently,
PineconeError
contains a lot of boilerplate for implementingstd::error::Error
. @haruska suggested we could maybe simplify some of the boilerplate using thethiserror
andanyhow
crates.Additionally, there was an enhancement filed (#54) to implement
Send
+Sync
forPineconeError
as currently we're unable to usePineconeError
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
Test Plan
New unit test added to verify that
PineoneError
has properly implemented theSend
andSync
traits.cargo test
-> validate CI passes as expected