def METHOD_NAME(problem_type, func):
    """Run a function. If it raises an acme_errors.ValidationError or messages.Error that
       contains the given problem_type, return. If it raises no error or the wrong
       error, raise an exception."""
    ok = False
    try:
        func()
    except messages.Error as e:
        if e.typ == problem_type:
            ok = True
        else:
            raise Exception("Expected %s, got %s" % (problem_type, e.__str__()))
    except acme_errors.ValidationError as e:
        for authzr in e.failed_authzrs:
            for chall in authzr.body.challenges:
                error = chall.error
                if error and error.typ == problem_type:
                    ok = True
                elif error:
                    raise Exception("Expected %s, got %s" % (problem_type, error.__str__()))
    if not ok:
        raise Exception('Expected %s, got no error' % problem_type)