move the check a bit up, in preparation for next commit

Change-Id: I9d7f98fecf96f162e2def0cd1af6931886fcb740
avoid infinite recursion when reading a broken file

Change-Id: Icb292ae4b4c286be52ee81e5d08b43efccb1892d