From 2349f0c92bcfcfc9d453c6bdcb5dee72576d9837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Schr=C3=B6der?= Date: Fri, 6 May 2022 15:07:43 +0200 Subject: [PATCH] ua: do not panic if the same extension object is registered multiple times --- ua/typereg.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ua/typereg.go b/ua/typereg.go index 7628a99a..0cf1242f 100644 --- a/ua/typereg.go +++ b/ua/typereg.go @@ -70,7 +70,7 @@ func (r *TypeRegistry) Lookup(v interface{}) *NodeID { // Register adds a new type to the registry. // -// If the id is already registered the function returns an error. +// If the id is already registered as a different type the function returns an error. // // Register panics if id is nil. func (r *TypeRegistry) Register(id *NodeID, v interface{}) error { @@ -84,8 +84,8 @@ func (r *TypeRegistry) Register(id *NodeID, v interface{}) error { typ := reflect.TypeOf(v) ids := id.String() - if r.types[ids] != nil { - return errors.Errorf("%s is already registered", id) + if cur := r.types[ids]; cur != nil && cur != typ { + return errors.Errorf("%s is already registered as %v", id, cur) } r.types[ids] = typ