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

Errors could use SWI messaging infrastructure. #59

Open
ghost opened this issue Jun 8, 2020 · 6 comments
Open

Errors could use SWI messaging infrastructure. #59

ghost opened this issue Jun 8, 2020 · 6 comments

Comments

@ghost
Copy link

ghost commented Jun 8, 2020

Also there is something strange that JPL doesn’t extend term_message//1. It has all the text directly inside the throw. But I guess the idea is that there is a message infrastructure that translates formal errors to text.

Maybe JPL could extend prolog:error_message//1. Don’t know what the official hook is. prolog:error_message//1 is probed by term_message//1, but prolog:error_message//1 is not further documented.

See also:
https://www.swi-prolog.org/pldoc/doc/_SWI_/boot/messages.pl?show=src#term_message//1

@ghost
Copy link
Author

ghost commented Jun 9, 2020

Here is an example of using the prolog:error_message//1 hook:

prolog:error_message(type_error(class_name_or_descriptor, Actual)) -->
    ['object, classname, descriptor or type expected, found `~p'''-[Actual]].

Which then gives me:

?- throw(error(type_error(class_name_or_descriptor,X),_)).
ERROR: object, classname, descriptor or type expected, found `_30228'

@ssardina
Copy link
Contributor

Hi @jburse . This seems to follow something else as you started with "Also..."

I am a bit lost of what this is about. Is the file you are linking from an old SWI version? I cannot find message.pl package or none of the predicates you mention. See the current doc:

https://www.swi-prolog.org/pldoc/man?section=printmsg

There are no matches for, for example, `error_message/1':

https://www.swi-prolog.org/search?for=error_message

Can you elaborate more?

@ghost
Copy link
Author

ghost commented Jun 10, 2020

The link works on my side. Try following the link from GitHub page, not
from notification E-mail, since I edited the link once. You should see:

Bildschirmfoto 2020-06-10 um 16 15 04

@ssardina
Copy link
Contributor

Ohh I see, yes. I found the file under /usr/lib/swi-prolog/boot/messages.pl, which is part of the SWI booting infrastructure.

There is not much documentation in SWIPL manual, if anything.

If I understand correctly, what you are suggesting is to improve the way that JPL throws exceptions, and instead of just putting the error in the text of the exception, build a set of structured errors (e.g., yours class_name_or_descriptor) and then use error_message/1 to give "semantics" (its proper text message) to each formal error?

Is this what you are proposing/suggesting? If so, it does make sense, would be nice indeed.

Now, seems you are talking about exceptions on the Prolog side, when Prolog calls JPL? There is another pack of exceptions on the Java side.

@JanWielemaker
Copy link
Member

There is not much documentation in SWIPL manual, if anything.

True. There is this tutorial: http://www.pathwayslms.com/swipltuts/message/index.html

If so, it does make sense, would be nice indeed.

I think that is the way to go. The PR by @dtonhofer works in that direction, but I don't think it introduces new types and domains, but instead (still) explains this using the comment arguments.

@ssardina
Copy link
Contributor

Great @JanWielemaker , thanks for that pointer, I think that should help a lot.

Now that I am finished with Dictionaries and Maven work, both work perfectly, I will look at that with @dtonhofer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants