def read_file()

in google_cloud_automlops/utils/utils.py [0:0]


def read_file(filepath: str) -> str:
    """Reads a file and returns contents as a string. Defaults to utf-8 encoding.

    Args:
        filepath (str): Path to the file.

    Returns:
        str: Contents of the file.

    Raises:
        Exception: An error is encountered while reading the file.
    """
    try:
        with open(filepath, 'r', encoding='utf-8') as file:
            contents = file.read()
        file.close()
    except FileNotFoundError as err:
        raise FileNotFoundError(f'Error reading file. {err}') from err
    return contents