Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Description is not necessary and handling BadNodeIdUnknown node in browse #705

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions examples/browse/browse.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"log"
"os"
"strconv"
"strings"

"github.com/gopcua/opcua"
"github.com/gopcua/opcua/debug"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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...)
}
Expand Down