Skip to content

Commit e64c277

Browse files
gautamg795Convex, Inc.
authored andcommitted
error handling changes
GitOrigin-RevId: 184aaa1ac8ee197bc82817b84d6b97296d39c6f8
1 parent 0ed1382 commit e64c277

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

crates/common/src/retriable_stream.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ where
6464
}
6565
anyhow::bail!("Attempted to clone RetriableStream after it has been polled")
6666
}
67+
68+
pub fn is_fresh(&self) -> bool {
69+
self.shared_inner.lock().is_some()
70+
}
6771
}
6872

6973
impl<T: TryStream + std::marker::Unpin> Stream for RetriableStream<T>

crates/errors/src/lib.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,10 @@ impl ErrorMetadata {
347347
self.code == ErrorCode::Forbidden
348348
}
349349

350+
pub fn is_misdirected_request(&self) -> bool {
351+
self.code == ErrorCode::MisdirectedRequest
352+
}
353+
350354
/// Return true if this error is deterministically caused by user. If so,
351355
/// we can propagate it into JS out of a syscall, and cache it if it is the
352356
/// full UDF result.
@@ -499,7 +503,7 @@ impl ErrorCode {
499503
ErrorCode::PaginationLimit => tonic::Code::InvalidArgument,
500504
ErrorCode::OutOfRetention => tonic::Code::OutOfRange,
501505
ErrorCode::OperationalInternalServerError => tonic::Code::Internal,
502-
ErrorCode::MisdirectedRequest => tonic::Code::InvalidArgument,
506+
ErrorCode::MisdirectedRequest => tonic::Code::FailedPrecondition,
503507
}
504508
}
505509

@@ -531,6 +535,7 @@ pub trait ErrorMetadataAnyhowExt {
531535
fn is_forbidden(&self) -> bool;
532536
fn should_report_to_sentry(&self) -> Option<(sentry::Level, Option<f64>)>;
533537
fn is_deterministic_user_error(&self) -> bool;
538+
fn is_misdirected_request(&self) -> bool;
534539
fn user_facing_message(&self) -> String;
535540
fn short_msg(&self) -> &str;
536541
fn msg(&self) -> &str;
@@ -618,6 +623,13 @@ impl ErrorMetadataAnyhowExt for anyhow::Error {
618623
false
619624
}
620625

626+
fn is_misdirected_request(&self) -> bool {
627+
if let Some(e) = self.downcast_ref::<ErrorMetadata>() {
628+
return e.is_misdirected_request();
629+
}
630+
false
631+
}
632+
621633
/// Returns the level at which the given error should report to sentry
622634
/// INFO -> it's a client-at-fault error
623635
/// WARNING -> it's a server-at-fault error that is expected

0 commit comments

Comments
 (0)