Improved error handling for files like #1282

@rafatower CR this, please