Skip to content

Commit

Permalink
Merge pull request #310 from zhujun98/improve_exception_handling
Browse files Browse the repository at this point in the history
Improve exception handling during client-server communication
  • Loading branch information
zhujun98 authored Jun 18, 2024
2 parents 3bb24a3 + d46fd57 commit 905a60b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
6 changes: 5 additions & 1 deletion gui/src/rpc_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,14 @@ bool RpcClient::checkStatus(const grpc::Status& status, bool warn_on_unavailable
const std::string& msg = status.error_message();
if (code == grpc::StatusCode::UNAVAILABLE) {
if (warn_on_unavailable_server) {
log::warn("Reconstruction server is not available!");
log::warn("Reconstruction server not available!");
}
} else if (code == grpc::StatusCode::INVALID_ARGUMENT){
log::error("Reconstruction server invalid argument: {}", msg);
} else if (code == grpc::StatusCode::RESOURCE_EXHAUSTED){
log::error("Reconstruction server resource exhausted: {}", msg);
} else if (code == grpc::StatusCode::UNKNOWN) {
log::error("Reconstruction server unknown error: {}", msg);
} else {
log::error("Unexpected RPC error {}: {}", code, msg);
std::exit(EXIT_FAILURE);
Expand Down
2 changes: 1 addition & 1 deletion recon/include/recon/projection_mediator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ProjectionMediator {

public:

ProjectionMediator(int capacity = 0);
explicit ProjectionMediator(int capacity = 0);

void push(DataType proj);

Expand Down
2 changes: 1 addition & 1 deletion recon/src/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ void Application::init() {

void Application::checkParams() {
if (orig_col_count_ <= 0 || orig_row_count_ <= 0 || angle_count_ <= 0) {
throw std::invalid_argument("Col count / Row count / Angle count must be positive!");
throw std::invalid_argument("Col count / Row count / Angle count must all be positive!");
}
}

Expand Down
23 changes: 11 additions & 12 deletions recon/src/rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ grpc::Status ControlService::StartAcquiring(grpc::ServerContext* /*context*/,
app_->startAcquiring();
return grpc::Status::OK;
} catch (const std::exception& e) {
spdlog::error("Failed to start acquiring!");
// FIXME
return {grpc::StatusCode::RESOURCE_EXHAUSTED, e.what()};
spdlog::error("Failed to start acquiring: {}", e.what());
return {grpc::StatusCode::UNKNOWN, e.what()};
}
}

Expand All @@ -40,9 +39,8 @@ grpc::Status ControlService::StopAcquiring(grpc::ServerContext* /*context*/,
app_->stopAcquiring();
return grpc::Status::OK;
} catch (const std::exception& e) {
spdlog::error("Failed to stop acquiring!");
// FIXME
return {grpc::StatusCode::RESOURCE_EXHAUSTED, e.what()};
spdlog::error("Failed to stop acquiring: {}", e.what());
return {grpc::StatusCode::UNKNOWN, e.what()};
}
}

Expand All @@ -52,10 +50,12 @@ grpc::Status ControlService::StartProcessing(grpc::ServerContext* /*context*/,
try {
app_->startProcessing();
return grpc::Status::OK;
} catch (const std::invalid_argument& e) {
spdlog::error("Failed to start processing: {}", e.what());
return {grpc::StatusCode::INVALID_ARGUMENT, e.what()};
} catch (const std::exception& e) {
spdlog::error("Failed to start processing!");
// FIXME
return {grpc::StatusCode::RESOURCE_EXHAUSTED, e.what()};
spdlog::error("Unknown exception: {}", e.what());
return {grpc::StatusCode::UNKNOWN, e.what()};
}
}

Expand All @@ -66,9 +66,8 @@ grpc::Status ControlService::StopProcessing(grpc::ServerContext* /*context*/,
app_->stopProcessing();
return grpc::Status::OK;
} catch (const std::exception& e) {
spdlog::error("Failed to stop processing!");
// FIXME
return {grpc::StatusCode::RESOURCE_EXHAUSTED, e.what()};
spdlog::error("Failed to stop processing: {}", e.what());
return {grpc::StatusCode::UNKNOWN, e.what()};
}
}

Expand Down

0 comments on commit 905a60b

Please sign in to comment.