Remove code duplication in error_messages_for.
Merge pull request #1394 from namusyaka/remove-code-duplication

Remove code duplication in error_messages_for.