From 02902e711df5ca3ee04d5bbb85289316100a105f Mon Sep 17 00:00:00 2001 From: Benjamin Rewis <32186188+benjirewis@users.noreply.github.com> Date: Mon, 25 Sep 2023 16:40:45 -0400 Subject: [PATCH] RSDK-4275 Handle `construct_resource` errors in module service (#154) --- src/viam/sdk/module/service.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/viam/sdk/module/service.cpp b/src/viam/sdk/module/service.cpp index dc04408b0..0facac22b 100644 --- a/src/viam/sdk/module/service.cpp +++ b/src/viam/sdk/module/service.cpp @@ -75,7 +75,11 @@ ::grpc::Status ModuleService_::AddResource(::grpc::ServerContext* context, const Dependencies deps = get_dependencies(this, request->dependencies()); const std::shared_ptr 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>& services = module->services(); if (services.find(cfg.api()) == services.end()) { @@ -127,8 +131,12 @@ ::grpc::Status ModuleService_::ReconfigureResource( const std::shared_ptr reg = Registry::lookup_model(cfg.name()); if (reg) { - const std::shared_ptr res = reg->construct_resource(deps, cfg); - manager->replace_one(cfg.resource_name(), res); + try { + const std::shared_ptr 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();