Fixed error reporting to include the stack trace