import json


def load_metadata(metadata_id, metadata_directory='./../data/metadata/'):
    """
        Loads a metadata file
    :param metadata_id: ID of the metadata file(stored in config)
    :param metadata_directory: Directory where the metadata file is stored
    :return: a json metadata file
    """
    path = metadata_directory + metadata_id + '.json'

    try:
        with open(path, 'r') as f:
            metadata = json.load(f)
        return metadata

    except FileNotFoundError:
        raise Exception('Metadata file at "{}" does not exist. Aborting.'.format(path))

    except json.decoder.JSONDecodeError as e:
        raise Exception(
            'Metadata file at "{}" contains errors. JSON could not be parsed. Aborting. Error message: {}'.format(path,
                                                                                                                  str(
                                                                                                                      e)))