Refactor error handling in object_schema