Dumps long stack traces for exceptions having a cause() method.

@param ex The exception.

@return A string representation of the error stack.
function getFullErrorStack(ex) {
  var ret = ex.stack;
  if(ex.cause && typeof(ex.cause) === 'function') {
    var cex = ex.cause();
    if(cex) {
      ret += '\nCaused by: ' + getFullErrorStack(cex);
    }
  }
  return ret;
}