From 59e156d7f971840614fde74df20aca80cbe51432 Mon Sep 17 00:00:00 2001 From: Ben Bredesen Date: Sat, 11 Mar 2023 12:24:05 -0600 Subject: [PATCH] logging and nil entry check, fixes #33 --- def/union_type.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/def/union_type.go b/def/union_type.go index 9e281b8..2a5a76f 100644 --- a/def/union_type.go +++ b/def/union_type.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/antchfx/xmlquery" + "github.com/sirupsen/logrus" "github.com/tidwall/gjson" ) @@ -76,7 +77,8 @@ func (t *unionType) PrintInternalDeclaration(w io.Writer) { var preamble, structDecl, epilogue strings.Builder if t.isReturnedOnly { - fmt.Fprintf(w, "// WARNING - union %s is returned only, which is not yet handled in the binding\n", t.PublicName()) + logrus.WithField("registry type", t.registryName). + Error("union is returned only, which is not yet handled in the binding") } // _vk type declaration @@ -154,7 +156,18 @@ func ReadUnionExceptionsFromJSON(exceptions gjson.Result, tr TypeRegistry, vr Va return true } // Ignore comments - UpdateUnionTypeFromJSON(key, exVal, tr[key.String()].(*unionType)) + if entry, found := tr[key.String()]; !found { + logrus.WithField("registry type", key.String()). + Warn("no existing registry type for union exception") + } else { + if entry.Category() != CatUnion { + logrus.WithField("registry type", key.String()). + WithField("category", entry.Category().String()). + Error("exception for union type was not a union in the registry") + } + + UpdateUnionTypeFromJSON(key, exVal, entry.(*unionType)) + } return true })