Ensure object isn't undefined

Hopefully error is always set if object is undefined. I think it's better to have a guard anyway.