def FormatErrorMessage(exc_name, status, code, reason, message, detail):
  """Formats an error message from components parsed by ParseErrorDetail."""
  if message and detail:
    return('%s: status=%d, code=%s, reason="%s", message="%s", detail="%s"' %
           (exc_name, status, code, reason, message, detail))
  if message:
    return('%s: status=%d, code=%s, reason="%s", message="%s"' %
           (exc_name, status, code, reason, message))
  if detail:
    return('%s: status=%d, code=%s, reason="%s", detail="%s"' %
           (exc_name, status, code, reason, detail))
  return('%s: status=%d, code=%s, reason="%s"' %
         (exc_name, status, code, reason))