Search code examples
pythonstatic-analysisparasoft

getting error: unable to load cross rule (invalid rule type or file does not exist)


I'm trying to load a custom rule within another custom rule, both made by the Parasoft rule wizard.

The following code is the python snippet that is placed in the calling rule as a method:

def somePythonMethod(node, context): 
   parent = context.getParentContext() 
   result = parent.executeRule("my_rule.rule", node) 

the error I retrieve upon running the analysis:

unable to load cross rule (invalid rule type or file does not exist)

followed by a link to the path of the rule, that does exist. Hence the problem I suppose has to do with the rule type.

What is the source of this error?


Solution

  • The parasoft docos recommend using something like the following:

       enf = node.getEnforcer()
       filename = node.getProperty("filename")
       line = node.getLine()
       col = node.getColumn()
       enf.executeRuleEx('./my.rule', node, filename, int(line), int(col))
    

    The difference being that you're calling executeRuleEx() on the enforcer not the parent node. Clearly too late for the OP but it might help anyone else asking the same question in future.