Ignoring errors is hardly ever the correct way of dealing with things.
Anyway, for those interested, the obvious fix is to check whether the group you are looking for is in the current list of groups instead of checking whether the nodename is in a specific group, so instead of: