Improved error handling in add_wrapper