docs: def attempt_file_write(
          path: str,
          contents: typing.Union[str, bytes],
          mode: str = 'w',
          offset: int = 0
  ) -> typing.Union[None, Exception]:
      """
      Attempts to write the specified contents to a file and returns None if
      successful, or the raised exception if writing failed.
      
      :param path:
          The path to the file that will be written
      :param contents:
          The contents of the file to write
      :param mode:
          The mode in which the file will be opened when written
      :param offset:
          The byte offset in the file where the contents should be written.
          If the value is zero, the offset information will be ignored and
          the operation will write entirely based on mode. Note that if you
          indicate an append write mode and an offset, the mode will be forced
          to write instead of append.
      :return:
          None if the write operation succeeded. Otherwise, the exception that
          was raised by the failed write action.
      """
      try:
          data = contents.encode()
      except Exception:
          data = contents
  
      if offset > 0:
          with open(path, 'rb') as f:
              existing = f.read(offset)
      else:
          existing = None
  
      append = 'a' in mode
      write_mode = 'wb' if offset > 0 or not append else 'ab'
      try:
          with open(path, write_mode) as f:
              if existing is not None:
                  f.write(existing)
              f.write(data)
          return None
      except Exception as error:
          return error