def try_get_error_code()

in deploy/ansible/filter_plugins/custom_filters.py [0:0]


def try_get_error_code(message, *args, **kwargs):
    try:
        tags = set()
        if args:
            tags = args[0]
        print(f"tags got from caller function = {tags}")
        tag_list = convert_kwargs_to_tags(kwargs)
        tag_list=tag_list.union(tags)
        print(f"tag_list = {tag_list}")
        for (matcher, op_message, valid_tags) in regex_to_error_msgs:
            if not valid_tags:
                valid_tags=set()
            print(f"valid_tags = {valid_tags}")
            if re.match(matcher, message):
                # if the tags supplied are in the list of valid tags
                # or the valid_tags set is empty (meaning the regex
                # conversion is valid for all tags), return the
                # converted message
                if tag_list.issubset(valid_tags) or len(valid_tags) == 0:
                    print(f"tag_list: {tag_list} is a subset of {valid_tags}")
                    return op_message
                else:
                    print(f"Invalid tag list. Valid tags = {valid_tags}, "+
                        f"supplied tag list = {tag_list}")
            else:
                print("regular expression could not be matched.")
    except:
        # Handle any unexpected exceptions while processing the error
        # messages
        traceback.print_exc()

    return message