fix #26 Check that error isn't nil before assigning

issue #26