Discussions related to Visual Prolog
User avatar
Ferenc Nagy
VIP Member
Posts: 215
Joined: 24 Apr 2007 12:26

What is the simplest counterpart of consulterror?

Unread post by Ferenc Nagy »

Hi
The good old PDC Prolog contained simple predicates showing the position of errors in consulted files:

Code: Select all

readtermerror(LineWithError,ErrorPosInLine)         (string,Unsigned) - (o,o)   consulterror(LineWithError,ErrorPosInLine,ErrorPosInFile)         (string,integer,ulong) - (o,o,o)
Using this and trap(...) I could easily show the erroneous data file and jump to the position of the error.
The current runtime exceptions

Code: Select all

runtime_exception::consult_WrongComment/3 runtime_exception::consult_WrongUsageOfKeyword/3

return very complicate structures.

Code: Select all

 getDescriptor_nd : (traceId TraceID) -> descriptor Descriptor nondeterm.     % @short Returns the descriptor.     % @end  
How can I simply extract the output

Code: Select all

LineWithError,ErrorPosInLine,ErrorPosInFile
from the descriptor structure?
TIA, Regards,
Frank Nagy
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

Have you read the Exception Handling tutorial?
Regards Thomas Linder Puls
PDC
User avatar
Ferenc Nagy
VIP Member
Posts: 215
Joined: 24 Apr 2007 12:26

Unread post by Ferenc Nagy »

Thomas Linder Puls wrote:Have you read the Exception Handling tutorial?
Yes, I have read it.

The exception descriptor gives the following information:
Property File Name
Style D:\Feri\TestDraw\Exe\erroneous.savs
Predicate Description
functorNotFoFunctor is not found in the domain
More Description
Functor is not found in the domain
Extra Info Extra Value
error code 309
ExtraInfo " The functor ' k ' is not in the domain ' pen_Style : : draw_options ' . The nearest context is : ' icture \ " , \ " Frame \ " , \ " Linans Serif ' "

Code: Select all

% 2013.12.09. Display descriptor of consulting error.     displayError(Property,FileName,Descriptor) :-         stdio::writef("%-12.12s%s","Property","File Name"),         stdio::nl,         stdio::writef("%-12.12s%s",Property,FileName),         stdio::nl,         Descriptor=exception::descriptor(_ClassInfo1,             exception::exceptionDescriptor(_ClassInfo2,             PredicateName, Description),             _Kind,ExtraInfo,_GMTTime,ExceptionDescription,             _ThreadId),         stdio::writef("%-12.12s%s","Predicate","Description"),         stdio::nl,         stdio::writef("%-12.12s%s",PredicateName,Description),         stdio::nl,         stdio::write("More Description"),         stdio::nl,         stdio::write(ExceptionDescription),         stdio::nl,         stdio::writef("%-12.12s%s","Extra Info","Extra Value"),         stdio::nl,         foreach list::getMember_nd(ExtraInfo) = namedValue(ExtraName,ExtraValue),             ExtraTokens=mystring::tokenize(toString(ExtraValue)),             list::length(ExtraTokens)>3,             listplus::split_before_last(ExtraTokens,Except_Last,_) do             list::drop(2,Except_Last)=Without_12,             stdio::writef("%-12.12s%s",ExtraName,string::concatWithDelimiter(Without_12," ")),             stdio::nl         end foreach,         stdio::nl.
I see the type of the error but I do not see the file and line position of the error.
TIA, Regards,
Frank Nagy
User avatar
Ferenc Nagy
VIP Member
Posts: 215
Joined: 24 Apr 2007 12:26

I simplified the display of the error descriptors

Unread post by Ferenc Nagy »

The following line contains semicolon instead of comma.
compose(p("Background";"Cut Edges","Lines","Style"),s(1,"Dashed","~ (Pen & Screen)")).
The output of the simplified error report:
The simplified code is:

Code: Select all

predicates % 2013.12.09. Display descriptor of consulting error.     displayError:(string Property, string FileName, exception::descriptor) procedure.   clauses   % 2013.12.09. Display descriptor of consulting error.     displayError(Property,FileName,Descriptor) :-         stdio::writef("%-12.12s %s","Property","File Name"),         stdio::nl,         stdio::writef("%-12.12s %s",Property,FileName),         stdio::nl,         Descriptor=exception::descriptor(_ClassInfo1,             exception::exceptionDescriptor(_ClassInfo2,             _PredicateName, _Description),             _Kind,ExtraInfo,_GMTTime,ExceptionDescription,             _ThreadId),         stdio::writef("%-12.12s %s","Message:", ExceptionDescription),         stdio::nl,         foreach list::getMember_nd(ExtraInfo) = namedValue(ExtraName,ExtraValue),             string::frontToken(toString(ExtraValue),_,Rest),             Body=string::trySubString(Rest,1,string::length(Rest)-2) do             stdio::writef("%-12.12s %s",ExtraName,Body),             stdio::nl         end foreach,         stdio::nl.    
I could filter out the duplicate contents of the errorDescription structure.

The position of the error within the file is hidden in the hidden source of string_native::vpiCore_consult.

This is a step back compared to the old consulterror predicate.

The advantage of the new consult is the possibility of comments and some extra spaces and empty lines among the terms:
% Test of consulting
compose(p("Picture","Frame","Lines","Style"), s(1,"Solid","Pen")).

The old one was very strict.
TIA, Regards,
Frank Nagy
User avatar
Ferenc Nagy
VIP Member
Posts: 215
Joined: 24 Apr 2007 12:26

The nearest context helps to find the error

Unread post by Ferenc Nagy »

I think I can close my topic with the following positive outcome.
The exception handling system gives the following ExtraInfo which helps to find the position of the error in a large consulted file.

ExtraInfo "Expected symbol ',', got ';' for domain 'collect_Settings::purpose'. The nearest context is: 'e\"),s(1,\"Solid\",\"Pented.'"
TIA, Regards,
Frank Nagy
Post Reply