Fixed Issue #1979

Improved the error message and added a test case.
Please review the changes.