Fix NameError in error-handling case

Fixes #268
Changelog re #268