Fix nil panic from using var when err exists (#6333)

(cherry picked from commit 6b00875ca8b4f3585c36bfb71ef8b8d172619e16)
1 file changed