Skip to content
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

catch errors / warnings on consult #105

Open
yochem opened this issue Sep 13, 2020 · 3 comments
Open

catch errors / warnings on consult #105

yochem opened this issue Sep 13, 2020 · 3 comments
Milestone

Comments

@yochem
Copy link

yochem commented Sep 13, 2020

Dear maintainer(s),

I am using your package for automating grading of students' homework. The basic procedure is like this:

  1. consult their file
  2. query our tests
  3. verify output queries

However, sometimes the students have errors or warnings on consulting. This should be catched by our program which can give feedback about this. Unfortunately I can't get this to work. I tried using the catcherrors parameter of the consult method, but that doesn't change anything. The warnings / errors are printed to stderr.

Do you know if this would be possible? I would love something like returning it from the consult method or something like that.

@tobiasgrubenmann
Copy link

Hi yochem,

I have a the same issue. I need to get an exception when there is an error in a consulted file.

After some investigation, I think the problem lies in SWI prolog itself. SWI Prolog doesn't raise an exception when there is a mistake in the consulted file and hence, pyswip cannot raise any exception neither.

I'm not sure about the rationale behind this behavior. But one explanation is that even when a prolog file contains errors, it is still "successfully" consulted up to the point where the first error occurs. I.e., all clauses preceding the one containing errors is still successfully added to the DB and you can use them.

In any case, I guess that you would have to ask the SWI prolog team directly to throw an exception when there is an error in a consulted file. Once this is implemented on the SWI prolog side, I would assume that this excecption is also automatically raised on the pyswip side.

Please be aware that everything I said above is my own conclusion after experimenting with SWI Prolog and pyswip and I don't know all the technical details. Hence, my conclusions could be wrong.

@allComputableThings
Copy link

Is it still same if you switch the catch_exception parameter?

@yochem
Copy link
Author

yochem commented Nov 19, 2020

pyswip doesn't seem to recognise that parameter:

>>> import pyswip
>>> pl = pyswip.Prolog()
>>> pl.consult('test.pl', catch_exception=True)
TypeError: consult() got an unexpected keyword argument 'catch_exception'
>>> pl.consult('test.pl', catchexception=True)
TypeError: consult() got an unexpected keyword argument 'catchexception'
>>> pl.consult('test.pl', catch_exceptions=True)
TypeError: consult() got an unexpected keyword argument 'catch_exceptions'
>>> pl.consult('test.pl', catchexceptions=True)
TypeError: consult() got an unexpected keyword argument 'catchexceptions'

@yuce yuce added this to the Backlog milestone Oct 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants