From 8beea77b3a34549b738e6b6a24180cdad4123ff0 Mon Sep 17 00:00:00 2001 From: Dan Gottlieb Date: Tue, 1 Oct 2024 10:04:50 -0400 Subject: [PATCH] RSDK-8889: Avoid user-error panic paths related to module API/Model registration. --- resource/resource_registry.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/resource/resource_registry.go b/resource/resource_registry.go index 282365f2bc5..6fbc59676be 100644 --- a/resource/resource_registry.go +++ b/resource/resource_registry.go @@ -270,7 +270,8 @@ func Register[ResourceT Resource, ConfigT ConfigValidator]( apiModel := APIModel{api, model} _, old := registry[apiModel] if old { - panic(errors.Errorf("trying to register two resources with same api: %q, model: %q", api, model)) + logging.Global().Errorw("An api, model pair is being double registered. Overwriting the old with the new.", + "api", api, "model", model) } if reg.Constructor == nil && reg.DeprecatedRobotConstructor == nil { panic(errors.Errorf("cannot register a nil constructor for api: %q, model: %q", api, model)) @@ -359,7 +360,8 @@ func RegisterAPI[ResourceT Resource](api API, creator APIRegistration[ResourceT] defer registryMu.Unlock() _, old := apiRegistry[api] if old { - panic(errors.Errorf("trying to register two of the same resource api: %s", api)) + logging.Global().Errorw("An api name is being double registered. Overwriting the old with the new.", + "api", api) } if creator.RPCServiceServerConstructor != nil && (creator.RPCServiceDesc == nil || creator.RPCServiceHandler == nil) {