Skip to content

Commit e6e5ac9

Browse files
gautamg795Convex, Inc.
authored andcommitted
fix error conversion
GitOrigin-RevId: e5516e15d9f6c606dc1a7164c0be36b401e5cd59
1 parent 940b1b2 commit e6e5ac9

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

crates/pb/src/error_metadata.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl TryFrom<ErrorMetadataProto> for ErrorMetadata {
8585
pub trait ErrorMetadataStatusExt {
8686
fn from_anyhow(error: anyhow::Error) -> Self;
8787
fn into_anyhow(self) -> anyhow::Error;
88-
fn context<C>(self, context: C) -> Self
88+
fn context<C>(self, context: C) -> anyhow::Error
8989
where
9090
C: Display + Send + Sync + 'static;
9191
}
@@ -124,12 +124,11 @@ impl ErrorMetadataStatusExt for tonic::Status {
124124
error
125125
}
126126

127-
fn context<C>(self, context: C) -> Self
127+
fn context<C>(self, context: C) -> anyhow::Error
128128
where
129129
C: Display + Send + Sync + 'static,
130130
{
131-
let anyhow_err = self.into_anyhow();
132-
Self::from_anyhow(anyhow_err.context(context))
131+
self.into_anyhow().context(context)
133132
}
134133
}
135134

@@ -183,10 +182,9 @@ mod tests {
183182

184183
#[test]
185184
fn test_context_no_error_metadata() {
186-
let status =
187-
tonic::Status::from_anyhow(anyhow::anyhow!("My special error")).context("Test context");
185+
let status = tonic::Status::from_anyhow(anyhow::anyhow!("My special error"));
188186

189-
let error = status.into_anyhow();
187+
let error = status.context("Test context");
190188
// Check the error we log to sentry includes the original error and the context
191189
let error_string = format!("{error:#}");
192190
assert!(error_string.contains("My special error"));
@@ -200,10 +198,9 @@ mod tests {
200198
fn test_context_with_error_metadata() {
201199
let status = tonic::Status::from_anyhow(
202200
ErrorMetadata::overloaded("ShortMsg", "Test long message").into(),
203-
)
204-
.context("Test context");
201+
);
205202

206-
let error = status.into_anyhow();
203+
let error = status.context("Test context");
207204
// Check the error we log to sentry includes the original error and the context
208205
let error_string = format!("{error:#}");
209206
assert!(error_string.contains("Test long message"));

0 commit comments

Comments
 (0)