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

Fix dynamic error types not being thread-safe #20

Merged
merged 3 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[workspace]
resolver = "2"

package.version = "0.2.0"
package.version = "0.2.1"
package.edition = "2021"
package.license = "Apache-2.0"

Expand Down
40 changes: 20 additions & 20 deletions crates/sdk/src/connector/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ pub enum InitializationError {
#[derive(Debug, Error)]
pub enum FetchMetricsError {
#[error("error fetching metrics: {0}")]
Other(Box<dyn Error>, serde_json::Value),
Other(Box<dyn Error + Send + Sync>, serde_json::Value),
}

impl FetchMetricsError {
pub fn new<E: Into<Box<dyn Error>>>(err: E) -> Self {
pub fn new<E: Into<Box<dyn Error + Send + Sync>>>(err: E) -> Self {
Self::Other(err.into(), serde_json::Value::Null)
}
#[must_use]
Expand Down Expand Up @@ -154,11 +154,11 @@ impl IntoResponse for FetchMetricsError {
#[derive(Debug, Error)]
pub enum HealthError {
#[error("error checking health status: {0}")]
Other(Box<dyn Error>, serde_json::Value),
Other(Box<dyn Error + Send + Sync>, serde_json::Value),
}

impl HealthError {
pub fn new<E: Into<Box<dyn Error>>>(err: E) -> Self {
pub fn new<E: Into<Box<dyn Error + Send + Sync>>>(err: E) -> Self {
Self::Other(err.into(), serde_json::Value::Null)
}
#[must_use]
Expand Down Expand Up @@ -190,11 +190,11 @@ impl IntoResponse for HealthError {
#[derive(Debug, Error)]
pub enum SchemaError {
#[error("error retrieving the schema: {0}")]
Other(Box<dyn Error>, serde_json::Value),
Other(Box<dyn Error + Send + Sync>, serde_json::Value),
}

impl SchemaError {
pub fn new<E: Into<Box<dyn Error>>>(err: E) -> Self {
pub fn new<E: Into<Box<dyn Error + Send + Sync>>>(err: E) -> Self {
Self::Other(err.into(), serde_json::Value::Null)
}
#[must_use]
Expand All @@ -205,8 +205,8 @@ impl SchemaError {
}
}

impl From<Box<dyn Error>> for SchemaError {
fn from(value: Box<dyn Error>) -> Self {
impl From<Box<dyn Error + Send + Sync>> for SchemaError {
fn from(value: Box<dyn Error + Send + Sync>) -> Self {
Self::new(value)
}
}
Expand Down Expand Up @@ -247,11 +247,11 @@ pub enum QueryError {
#[error("unsupported operation: {}", .0.message)]
UnsupportedOperation(models::ErrorResponse),
#[error("error executing query: {0}")]
Other(Box<dyn Error>, serde_json::Value),
Other(Box<dyn Error + Send + Sync>, serde_json::Value),
}

impl QueryError {
pub fn new<E: Into<Box<dyn Error>>>(err: E) -> Self {
pub fn new<E: Into<Box<dyn Error + Send + Sync>>>(err: E) -> Self {
Self::Other(err.into(), serde_json::Value::Null)
}
pub fn new_invalid_request<T: ToString>(message: &T) -> Self {
Expand Down Expand Up @@ -289,8 +289,8 @@ impl QueryError {
}
}

impl From<Box<dyn Error>> for QueryError {
fn from(value: Box<dyn Error>) -> Self {
impl From<Box<dyn Error + Send + Sync>> for QueryError {
fn from(value: Box<dyn Error + Send + Sync>) -> Self {
Self::new(value)
}
}
Expand Down Expand Up @@ -334,11 +334,11 @@ pub enum ExplainError {
#[error("unsupported operation: {}", .0.message)]
UnsupportedOperation(models::ErrorResponse),
#[error("explain error: {0}")]
Other(Box<dyn Error>, serde_json::Value),
Other(Box<dyn Error + Send + Sync>, serde_json::Value),
}

impl ExplainError {
pub fn new<E: Into<Box<dyn Error>>>(err: E) -> Self {
pub fn new<E: Into<Box<dyn Error + Send + Sync>>>(err: E) -> Self {
Self::Other(err.into(), serde_json::Value::Null)
}
pub fn new_invalid_request<T: ToString>(message: &T) -> Self {
Expand Down Expand Up @@ -376,8 +376,8 @@ impl ExplainError {
}
}

impl From<Box<dyn Error>> for ExplainError {
fn from(value: Box<dyn Error>) -> Self {
impl From<Box<dyn Error + Send + Sync>> for ExplainError {
fn from(value: Box<dyn Error + Send + Sync>) -> Self {
Self::new(value)
}
}
Expand Down Expand Up @@ -429,11 +429,11 @@ pub enum MutationError {
#[error("mutation violates constraint: {}", .0.message)]
ConstraintNotMet(models::ErrorResponse),
#[error("error executing mutation: {0}")]
Other(Box<dyn Error>, serde_json::Value),
Other(Box<dyn Error + Send + Sync>, serde_json::Value),
}

impl MutationError {
pub fn new<E: Into<Box<dyn Error>>>(err: E) -> Self {
pub fn new<E: Into<Box<dyn Error + Send + Sync>>>(err: E) -> Self {
Self::Other(err.into(), serde_json::Value::Null)
}
pub fn new_invalid_request<T: ToString>(message: &T) -> Self {
Expand Down Expand Up @@ -489,8 +489,8 @@ impl MutationError {
}
}

impl From<Box<dyn Error>> for MutationError {
fn from(value: Box<dyn Error>) -> Self {
impl From<Box<dyn Error + Send + Sync>> for MutationError {
fn from(value: Box<dyn Error + Send + Sync>) -> Self {
Self::new(value)
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/sdk/src/default_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,15 +448,15 @@ mod ndc_test_commands {
) -> Result<ndc_models::CapabilitiesResponse, ndc_test::error::Error> {
super::get_capabilities::<C>()
.await
.into_value::<Box<dyn std::error::Error>>()
.map_err(ndc_test::error::Error::OtherError)
.into_value::<Box<dyn std::error::Error + Send + Sync>>()
.map_err(|e| ndc_test::error::Error::OtherError(e))
}

async fn get_schema(&self) -> Result<ndc_models::SchemaResponse, ndc_test::error::Error> {
match C::get_schema(&self.configuration).await {
Ok(response) => response
.into_value::<Box<dyn std::error::Error>>()
.map_err(ndc_test::error::Error::OtherError),
.into_value::<Box<dyn std::error::Error + Send + Sync>>()
.map_err(|e| ndc_test::error::Error::OtherError(e)),
Err(err) => Err(ndc_test::error::Error::OtherError(err.into())),
}
}
Expand Down
4 changes: 3 additions & 1 deletion crates/sdk/src/json_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ impl<A: (for<'de> serde::Deserialize<'de>)> JsonResponse<A> {
///
/// This is only intended for testing and compatibility. If it lives on a
/// critical path, we recommend you avoid it.
pub(crate) fn into_value<E: From<Box<dyn std::error::Error>>>(self) -> Result<A, E> {
pub(crate) fn into_value<E: From<Box<dyn std::error::Error + Send + Sync>>>(
self,
) -> Result<A, E> {
match self {
Self::Value(value) => Ok(value),
Self::Serialized(bytes) => {
Expand Down
Loading