def _add_record_information()

in dataplex-quickstart-labs/00-resources/scripts/python/business-glossary-import/bg_import/error.py [0:0]


  def _add_record_information(self) -> str:
    """Generate an string with information about the record and its error.

    Returns:
      String containing the full record that generates an error and the location
      where the error exists signaled.
    """
    if not self.record:
      return ""

    # For empty fields, we increase the size to two empty characters to be
    # able to display where the issue is
    if not self.record[self.column - 1]:
      self.record[self.column - 1] = " " * 2
    join_record = ", ".join(self.record)
    # Number of space characters to add before the field with the issue
    chars_before_error = sum(
        [len(self.record[i]) for i in range(self.column - 1)]
    )
    chars_before_error += 2 * (self.column - 1)
    # Number of ^ chars to insert
    chars_error = len(self.record[self.column - 1])
    # Number of space characters to add after the field with the issue
    chars_after_error = len(join_record) - chars_before_error - chars_error

    error_mark = (
        f"{' ' * chars_before_error}"
        f"{'^' * chars_error}"
        f"{' ' * chars_after_error}"
    )

    # If the length of the join record is longer than _MAX_CHARS_PER_LINE
    # we split it into separate lines
    err = []
    for i in range(0, len(join_record), _MAX_CHARS_PER_LINE):
      err.append(
          (
              f"{join_record[i : (i + _MAX_CHARS_PER_LINE)]}\n"
              f"{error_mark[i : (i + _MAX_CHARS_PER_LINE)]}\n"
          )
      )
    return ("").join(err)