Check if an image with a given tag exists. No side-effects. Idempotent.
    Handles ImageNotFound and APIError exceptions, but only reraises APIError.

def getImageByTag(tag):
    '''Check if an image with a given tag exists. No side-effects. Idempotent.
    Handles ImageNotFound and APIError exceptions, but only reraises APIError.
    '''
    require_str("tag", tag)

    image = None
    try:
        image = client.images.get(tag)
        print("Found image", tag, "...")
    except ImageNotFound:
        print("Image", tag, "does not exist ...")
    except APIError as exc:
        eprint("Unhandled error while getting image", tag)
        raise exc

    return image