Move error check for unset variable

In preparation for possible inlining