Skip to content

jsonpath-ng incorrectly parsing the P4IRTree.program JSON #697

@peterbailey-arista

Description

@peterbailey-arista

I opened an issue in the jsonpath-ng package as well because I believe this to be the root cause
h2non/jsonpath-ng#216

When P4IRTree.walk calls jsonpath_exp.find(self.program) the returned matches have stripped the original JSON dictionary's formatting and there are lists in the place of dicts, this causes an indexing error later when "Source_Info" is read

Traceback (most recent call last):
08:46:42    File "dash-sai/DASH/dash-pipeline/SAI/./sai_api_gen.py", line 44, in <module>
08:46:42      var_ref_graph = P4VarRefGraph(p4ir)
08:46:42                      ^^^^^^^^^^^^^^^^^^^
08:46:42    File "dash-sai/DASH/dash-pipeline/SAI/utils/p4ir/p4ir_var_ref_graph.py", line 15, in __init__
08:46:42      self.__build_graph()
08:46:42    File "dash-sai/DASH/dash-pipeline/SAI/utils/p4ir/p4ir_var_ref_graph.py", line 18, in __build_graph
08:46:42      self.__build_counter_list()
08:46:42    File "dash-sai/DASH/dash-pipeline/SAI/utils/p4ir/p4ir_var_ref_graph.py", line 28, in __build_counter_list
08:46:42      self.ir.walk(
08:46:42    File "dash-sai/DASH/dash-pipeline/SAI/utils/p4ir/p4ir_tree.py", line 18, in walk
08:46:42      on_match(match)
08:46:42    File "dash-sai/DASH/dash-pipeline/SAI/utils/p4ir/p4ir_var_ref_graph.py", line 24, in on_counter_definition
08:46:42      ir_value = P4IRVarInfo.from_ir(match.value)
08:46:42                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
08:46:42    File "dash-sai/DASH/dash-pipeline/SAI/utils/p4ir/p4ir_var_info.py", line 11, in from_ir
08:46:42      ir_def_node["Source_Info"]["source_fragment"],
08:46:42      ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
08:46:42  TypeError: list indices must be integers or slices, not str

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions