Skip to main content
 首页 » 编程设计

python之收到错误 : unable to load cross rule (invalid rule type or file does not exist)

2025年05月04日17insus

我正在尝试在另一个自定义规则中加载自定义规则,这两个规则均由 Parasoft 规则向导创建。

以下代码是作为方法放在调用规则中的python片段:

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

我在运行分析时检索到的错误:

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

后跟指向规则路径的链接,该规则确实存在。 因此,我认为问题与规则类型有关。

此错误的来源是什么?

请您参考如下方法:

parasoft docos 建议使用如下内容:

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

不同之处在于您是在执行者而不是父节点上调用 executeRuleEx()。对于 OP 来说显然为时已晚,但它可能会帮助其他人在未来提出同样的问题。