improve error logging by including stack trace if available