Improve error message when a function is applied