You should do the res.nil? check before this line.