From d6a7d56794e056abc2dd179c6e06577125610225 Mon Sep 17 00:00:00 2001 From: Yang Guang Date: Wed, 17 Jan 2024 14:47:19 +0800 Subject: [PATCH] description is not necessary and handle BadNodeIdUnknown node --- examples/browse/browse.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/examples/browse/browse.go b/examples/browse/browse.go index 27826b2d..376298df 100644 --- a/examples/browse/browse.go +++ b/examples/browse/browse.go @@ -11,6 +11,7 @@ import ( "log" "os" "strconv" + "strings" "github.com/gopcua/opcua" "github.com/gopcua/opcua/debug" @@ -76,7 +77,10 @@ func browse(ctx context.Context, n *opcua.Node, path string, level int) ([]NodeD switch err := attrs[2].Status; err { case ua.StatusOK: - def.Description = attrs[2].Value.String() + // Not everyone input description + if attrs[2].Value != nil { + def.Description = attrs[2].Value.String() + } case ua.StatusBadAttributeIDInvalid: // ignore default: @@ -146,7 +150,20 @@ func browse(ctx context.Context, n *opcua.Node, path string, level int) ([]NodeD for _, rn := range refs { children, err := browse(ctx, rn, def.Path, level+1) if err != nil { - return errors.Errorf("browse children: %s", err) + //Handling the errors of bad node id + if err == ua.StatusBadNodeIDUnknown { + browseName := strings.Split(rn.String(), def.BrowseName+".")[1] + children := NodeDef{ + BrowseName: browseName, + Path: join(def.Path, browseName), + NodeID: ua.NewStringNodeID(rn.ID.Namespace(), "BadNodeIdUnknown (0x80340000)"), + Description: "BadNodeIdUnknown (0x80340000)", + Writable: false, + } + + nodes = append(nodes, children) + } + continue } nodes = append(nodes, children...) }