Improve error handling in set_option