import functools
import codecs


def get_file_contents(source_path: str) -> str:
    """
    Loads the contents of the source into a string for execution using multiple
    loading methods to handle cross-platform encoding edge cases. If none of
    the load methods work, a string is returned that contains an error function
    response that will be displayed when the step is run alert the user to the
    error.

    :param source_path:
        Path of the step file to load.
    """
    open_funcs = [
        functools.partial(codecs.open, source_path, encoding='utf-8'),
        functools.partial(open, source_path, 'r')
    ]

    for open_func in open_funcs:
        try:
            with open_func() as f:
                return f.read()
        except Exception:
            pass

    return (
        'raise IOError("Unable to load step file at: {}")'
        .format(source_path)
    )