-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error handling behaving differently for rule syntax and python code #48
Comments
CLIPS does not implement exceptions. Therefore, it won't raise any The reason why you see a What is happening is your function throws the error and stops the execution of your CLIPS rules. This mechanism is silent and the only way for you to verify whether everything ran smoothly is via the CLIPS env = clips.Environment()
try:
env.define_function(is_date_in_range)
env.build(rule)
env.assert_string("(issue_date \"gibberish\")")
env.run()
print(env.eval('(get-error)'))
except Exception as error:
print("Found an error") Will print:
Nevertheless, the mechanism is indeed imperfect and the library should be more explicit when handling these situations. I will soon come with improvements in merit. |
Awesome! Thanks for the answer, that will already help me proceed with my developments! |
Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
When exceptions happen in a Python defined function, the execution of the Rule is interrupted. The error and traceback are logged on `stdwrn` routers and the error message is forwarded back to CLIPS. A new set of API `error_state` and `clear_error_state()` are provided to check if errors during rule execution happened. Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
Issue fixed in release |
Hello! I new to clipspy and I am currently designing some rules based on dates.
When running my test scenarios with invalid dates, I noticed that exceptions throw by my python code are not reaching my
except
clause.The simplified example is:
In this code snippet I am asserting
gibberish
to force the error onis_date_in_range
, which is thrown, but my application ends without printingcondition satisfied
neithercondition not satisfied
neitherFound an error
.If I debug
is_date_in_range
I can see on the console:On the other hand if I purposefully add a typo to my if statement, like
if (eqq ?is_date_in_range TRUE) then
, then I also won't see thecondition satisfied
neithercondition satisfied
, but I'll be able to catchCLIPSError
and see theFound an error
message printed.I am running this snippet using Python 3.7.11 on MAC and also on Debian image, both showing the same results.
Am I missing some configuration that would allow me to catch it? I understand that defensive programming would be a better solution in this case, but I am concerned that my service won't be aware of unexpected errors.
Thanks in advance!
The text was updated successfully, but these errors were encountered: