convert KeyError to AttributeError