Fix tests crash in DebugMode recently introduced.

Now we keep the original error message type and just add more information to it.
Merge pull request #1645 from nouiz/debugmode

Fix tests crash in DebugMode recently introduced.