Add a simple assert() check that arguments passed to node.localIndex(...) are not out of bounds.
assert()
node.localIndex(...)