Skip to content

Commit

Permalink
RSDK-4275 Handle construct_resource errors in module service (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjirewis authored Sep 25, 2023
1 parent 31bed7f commit 02902e7
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/viam/sdk/module/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ ::grpc::Status ModuleService_::AddResource(::grpc::ServerContext* context,
const Dependencies deps = get_dependencies(this, request->dependencies());
const std::shared_ptr<ModelRegistration> reg = Registry::lookup_model(cfg.api(), cfg.model());
if (reg) {
res = reg->construct_resource(deps, cfg);
try {
res = reg->construct_resource(deps, cfg);
} catch (const std::exception& exc) {
return grpc::Status(::grpc::INTERNAL, exc.what());
}
};
const std::unordered_map<API, std::shared_ptr<ResourceManager>>& services = module->services();
if (services.find(cfg.api()) == services.end()) {
Expand Down Expand Up @@ -127,8 +131,12 @@ ::grpc::Status ModuleService_::ReconfigureResource(

const std::shared_ptr<ModelRegistration> reg = Registry::lookup_model(cfg.name());
if (reg) {
const std::shared_ptr<Resource> res = reg->construct_resource(deps, cfg);
manager->replace_one(cfg.resource_name(), res);
try {
const std::shared_ptr<Resource> res = reg->construct_resource(deps, cfg);
manager->replace_one(cfg.resource_name(), res);
} catch (const std::exception& exc) {
return grpc::Status(::grpc::INTERNAL, exc.what());
}
}

return grpc::Status();
Expand Down

0 comments on commit 02902e7

Please sign in to comment.