Handle errors in codegen more gracefully