Fixes bug where sql didn't always show in error handling