On 28/04/18 16:06, Volker Wysk wrote:
> Am Samstag, 28. April 2018, 14:45:21 CEST schrieb Jan Wielemaker:
>> Not sure how to improve much as the error term is dictated by the
>> standard (well, almost as absolute_file_name/3 is not in the
>> standard).
>
> The error message is dictated? (the "error term"?) Really ...
The standard says that BIP (Built in predicates) produce exceptions of
the form error(Formal, ImplementationDependent), where Formal is
dictated by the standard and ImplementationDependent is left to the
implementation. Formal are a number of terms, one of which is
existence_error(TypeOfObject, Object). It defines a number of
TypeOfObject values, one of which is `source_sink` which (I my
interpretation) is an abstraction of "file".
Of course the standard can only describe the errors for defined
BIPs. I (and most other Prologs AFAIK) try to reuse the standard
error terms as much as possible for other BIPS. That leaves little
choice but raising
error(existence_error(source_sink, bar),
ImplementationDependent)
ImplementationDependent varies wildly between systems. In SWI-Prolog the
code raising the error typically leaves it unbound or binds it to
context(_, Message). The library(prolog_stack) decorates the exception
with a stack trace if it is uncaught and unifies with the shape
context(Stack, _). Finally, print_message/2 turns all this into a
message for the console.
So yes, in theory the system could add additional information in the
Message part of the context term. This is used sparsely. Possibly too
sparsely. A big obstacle is that this is really a lot of work and
requires a lot of thought to get something consistent. If you want to be
consistent you probably have to catch and rethrow errors in higher BIPs
to make the message fit the context. That is a lot of code that makes
the sources less readable and the system bigger and slower.
This is for programmers, so in how many ways can you interpret the fact
that absolute_file_name(bar, ...) tells you that the `source_sink` `bar`
doesn't exist?
I surely agree that interpreting error messages is not really easy and
typically highly system specific. What about "Warning: your head is
detached" by GIT :) It is also true that systems are getting better
in error messages and that has a lot of value to novice users.
My intuition would tell me that the way to go is to write a library that
translates the entire error term (formal, stack and message) to
something nice and crisp for novices. That is quite a challenge though.
In this case the rule set could reason that source_sink in the context
of absolute_file_name/3 means "file" (or "directory" if the
file_type(directory) was given) and the "file" "bar" doesn't exist while
"bar" exists but is a directory rather than a file. So, we get:
ERROR: The regular file "bar" doesn't exist. "bar" exists as a
directory.
ERROR: Use the option file_type(directory) to match directories.
It would be great to have something like that!
Cheers --- Jan