@@ -85,7 +85,7 @@ impl TryFrom<ErrorMetadataProto> for ErrorMetadata {
85
85
pub trait ErrorMetadataStatusExt {
86
86
fn from_anyhow ( error : anyhow:: Error ) -> Self ;
87
87
fn into_anyhow ( self ) -> anyhow:: Error ;
88
- fn context < C > ( self , context : C ) -> Self
88
+ fn context < C > ( self , context : C ) -> anyhow :: Error
89
89
where
90
90
C : Display + Send + Sync + ' static ;
91
91
}
@@ -124,12 +124,11 @@ impl ErrorMetadataStatusExt for tonic::Status {
124
124
error
125
125
}
126
126
127
- fn context < C > ( self , context : C ) -> Self
127
+ fn context < C > ( self , context : C ) -> anyhow :: Error
128
128
where
129
129
C : Display + Send + Sync + ' static ,
130
130
{
131
- let anyhow_err = self . into_anyhow ( ) ;
132
- Self :: from_anyhow ( anyhow_err. context ( context) )
131
+ self . into_anyhow ( ) . context ( context)
133
132
}
134
133
}
135
134
@@ -183,10 +182,9 @@ mod tests {
183
182
184
183
#[ test]
185
184
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" ) ) ;
188
186
189
- let error = status. into_anyhow ( ) ;
187
+ let error = status. context ( "Test context" ) ;
190
188
// Check the error we log to sentry includes the original error and the context
191
189
let error_string = format ! ( "{error:#}" ) ;
192
190
assert ! ( error_string. contains( "My special error" ) ) ;
@@ -200,10 +198,9 @@ mod tests {
200
198
fn test_context_with_error_metadata ( ) {
201
199
let status = tonic:: Status :: from_anyhow (
202
200
ErrorMetadata :: overloaded ( "ShortMsg" , "Test long message" ) . into ( ) ,
203
- )
204
- . context ( "Test context" ) ;
201
+ ) ;
205
202
206
- let error = status. into_anyhow ( ) ;
203
+ let error = status. context ( "Test context" ) ;
207
204
// Check the error we log to sentry includes the original error and the context
208
205
let error_string = format ! ( "{error:#}" ) ;
209
206
assert ! ( error_string. contains( "Test long message" ) ) ;
0 commit comments