在 PyClips 中传播剪辑错误消息

发布于 2024-09-24 01:39:27 字数 1035 浏览 0 评论 0原文

我发现使用 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

如何让 PyC​​lips 给出由 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不知在何时 2024-10-01 01:39:27

捕获 ClipsError,然后阅读 ErrorStream 了解详细信息。例如:

engine = clips.Environment()
engine.Reset()
engine.Clear()
try:
    engine.Load(os.path.abspath(rule_file))
except clips.ClipsError:
    logging.error(clips.ErrorStream.Read())

Catch the ClipsError, then read ErrorStream for the details. For example:

engine = clips.Environment()
engine.Reset()
engine.Clear()
try:
    engine.Load(os.path.abspath(rule_file))
except clips.ClipsError:
    logging.error(clips.ErrorStream.Read())
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文