import json


def read_json_file(datafile):
    """
    Read in given JSON file from the filesystem; handle any errors
    during processing properly
    """

    try:
        with open(datafile) as fh:
            return json.loads(fh.read())
    except FileNotFoundError:
        raise RuntimeError(
            f'Unable to open metadata file {datafile}'
        )
    except json.decoder.JSONDecodeError:
        raise RuntimeError(
            f'Invalid JSON in metadata file {datafile}'
        )