def parse_unit_change(action, data, current_status):
    """Parse the given unit change.

    The change is represented by the given action/data pair.
    Also receive the last known unit status which can be empty if the unit
    status is not yet known.

    Output a human readable message each time a relevant change is found.

    Return the unit status and the identifier of the machine hosting the unit.
    Raise a ValueError if the service unit is removed or in an error state.
    """
    unit_name = data['Name']
    if action == 'remove':
        msg = '{} unexpectedly removed'.format(unit_name)
        raise ValueError(msg.encode('utf-8'))
    status = data['Status']
    if 'error' in status:
        msg = '{} is in an error state: {}: {}'.format(unit_name, status,
            data['StatusInfo'])
        raise ValueError(msg.encode('utf-8'))
    if status != current_status:
        if status == 'pending':
            print('{} deployment is pending'.format(unit_name))
        elif status == 'installed':
            print('{} is installed'.format(unit_name))
        elif status == 'started':
            print('{} is ready on machine {}'.format(unit_name, data[
                'MachineId']))
    return status, data.get('MachineId', '')
