Skip to content

Commit

Permalink
[ENH] Propagate error codes through rust services
Browse files Browse the repository at this point in the history
  • Loading branch information
HammadB committed Sep 25, 2024
1 parent fe32510 commit d90661c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions rust/error/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ edition = "2021"
path = "src/lib.rs"

[dependencies]
tonic = { workspace = true }
25 changes: 25 additions & 0 deletions rust/error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,28 @@ impl ChromaError for Box<dyn ChromaError> {
self.as_ref().code()
}
}

impl From<ErrorCodes> for tonic::Code {
fn from(err: ErrorCodes) -> tonic::Code {
match err {
ErrorCodes::Success => tonic::Code::Ok,
ErrorCodes::Cancelled => tonic::Code::Cancelled,
ErrorCodes::Unknown => tonic::Code::Unknown,
ErrorCodes::InvalidArgument => tonic::Code::InvalidArgument,
ErrorCodes::DeadlineExceeded => tonic::Code::DeadlineExceeded,
ErrorCodes::NotFound => tonic::Code::NotFound,
ErrorCodes::AlreadyExists => tonic::Code::AlreadyExists,
ErrorCodes::PermissionDenied => tonic::Code::PermissionDenied,
ErrorCodes::ResourceExhausted => tonic::Code::ResourceExhausted,
ErrorCodes::FailedPrecondition => tonic::Code::FailedPrecondition,
ErrorCodes::Aborted => tonic::Code::Aborted,
ErrorCodes::OutOfRange => tonic::Code::OutOfRange,
ErrorCodes::Unimplemented => tonic::Code::Unimplemented,
ErrorCodes::Internal => tonic::Code::Internal,
ErrorCodes::Unavailable => tonic::Code::Unavailable,
ErrorCodes::DataLoss => tonic::Code::DataLoss,
ErrorCodes::Unauthenticated => tonic::Code::Unauthenticated,
ErrorCodes::VersionMismatch => tonic::Code::Internal,
}
}
}
26 changes: 14 additions & 12 deletions rust/worker/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,11 @@ impl WorkerServer {
let result = match result {
Ok(result) => result,
Err(e) => {
return Err(Status::internal(format!(
"Error running orchestrator: {}",
e
)));
tracing::error!("Error running orchestrator: {}", e);
return Err(Status::new(
e.code().into(),
format!("Error running orchestrator: {}", e),
));
}
};

Expand Down Expand Up @@ -308,10 +309,11 @@ impl WorkerServer {
let mut result = match result {
Ok(result) => result,
Err(e) => {
return Err(Status::internal(format!(
"Error running orchestrator: {}",
e
)));
tracing::error!("Error running orchestrator: {}", e);
return Err(Status::new(
e.code().into(),
format!("Error running orchestrator: {}", e),
));
}
};

Expand Down Expand Up @@ -435,10 +437,10 @@ impl WorkerServer {
Ok(result) => result,
Err(e) => {
tracing::error!("Error running orchestrator: {}", e);
return Err(Status::internal(format!(
"Error running orchestrator: {}",
e
)));
return Err(Status::new(
e.code().into(),
format!("Error running orchestrator: {}", e),
));
}
};

Expand Down

0 comments on commit d90661c

Please sign in to comment.