improve cfunction error messages, closes #2596