在 PyClips 中传播剪辑错误消息
我发现使用 PyClips 进行开发非常困难,因为它似乎用通用的“语法错误”消息替换了 Clips 抛出的有用错误消息。这使得使用 PyClips 时在大型代码库上进行调试非常费力并且几乎不可能。
考虑以下示例。我写了一个非常大的表达式,其中包含乘法运算符,但我错误地忘记添加第二个参数。 PyClips 并没有简单地告诉我缺少参数,而是告诉我存在语法错误。本来应该花 1 秒才能改正的问题,我花了 5 分钟才改正,因为我在我的大表情中寻找着错误。
这是一个精简版本:
在 Clips 中,有一条有用的错误消息:
clips
CLIPS> (defrule myrule "" (myfact 123) => (bind ?prob (* (min 1 2))))
[ARGACCES4] Function * expected at least 2 argument(s)
ERROR:
(defrule MAIN::myrule ""
(myfact 123)
=>
(bind ?prob (* (min 1 2))
在 PyClips 中,有一条无用的错误消息:
python
>>> import clips
>>> clips.BuildRule('myrule','(myfact 123)','(bind ?prob (* (min 1 2)))','')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/clips/_clips_wrap.py", line 2839, in BuildRule
_c.build(construct)
_clips.ClipsError: C08: syntax error, or unable to parse expression
如何让 PyClips 给出由 Clips 抛出的真实错误?
I'm finding it very difficult to develop with PyClips, because it appears to replace useful error messages thrown by Clips with a generic "syntax error" message. This makes debugging very laborious and practically impossible on large codebases when using PyClips.
Consider the following example. I wrote a very large expression, which contained the multiplication operator, but I mistakenly forgot to add the second argument. Instead of simply telling I was missing an argument, PyClips told me there was a syntax error. What should have taken me 1 second to correct, took me 5 minutes to correct as I hunted through my large expression, looking for the mistake.
Here's a condensed version:
In Clips, with a useful error message:
clips
CLIPS> (defrule myrule "" (myfact 123) => (bind ?prob (* (min 1 2))))
[ARGACCES4] Function * expected at least 2 argument(s)
ERROR:
(defrule MAIN::myrule ""
(myfact 123)
=>
(bind ?prob (* (min 1 2))
And in PyClips, with an unuseful error message:
python
>>> import clips
>>> clips.BuildRule('myrule','(myfact 123)','(bind ?prob (* (min 1 2)))','')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/clips/_clips_wrap.py", line 2839, in BuildRule
_c.build(construct)
_clips.ClipsError: C08: syntax error, or unable to parse expression
How can I get PyClips to give me the real error thrown by Clips?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
捕获 ClipsError,然后阅读 ErrorStream 了解详细信息。例如:
Catch the ClipsError, then read ErrorStream for the details. For example: