Backport 51443: Handle a few more error conditions.
Backport 51443:
Handle a few more error conditions.

Klocwork 301 and 302.  Will backport.

sk-/python2.7-type-annotator,sk-/python2.7-type-annotator,sk-/python2.7-type-annotator