Be more careful with AttrubuteErrors

AttributeError should be caught as close to the place where it may
be raised as possible to avoid hiding real bugs.

Change-Id: I992e9674673fe1ed2376c46bb68fb63bd077db24
Merge "Be more careful with AttrubuteErrors"