Add stacktrace to error log.

This is the remains of a previous PR that had conflicts...