Improve error message in deriving (fix Trac #2851)