def _FormatPipelineErrorResult(result):
  """Formats a kpt pipeline error result.

  Args:
    result: The pipeline error result object.

  Returns:
    string. The formatted result string, including the resource, file, and
      field that the result references, as applicable.

  """
  prefix = '  - Error'

  file = result.get('file')
  if file and 'path' in file:
    prefix += ' in file "{}"'.format(file.get('path'))

  resource_ref = result.get('resourceRef')
  if resource_ref:
    resource = '{}/{}/{}'.format(
        resource_ref.get('apiVersion'), resource_ref.get('kind'),
        resource_ref.get('name'))
    prefix += ' in resource "{}"'.format(resource)

  field = result.get('field')
  if field:
    prefix += ' in field "{}"'.format(field)

  msg = result.get('message')
  return '{}:\n      "{}"'.format(prefix, msg)