error handling

This commit is contained in:
Vitor Santos Costa 2018-07-02 15:20:17 +01:00
parent 53de04c38f
commit 71aed8b870
4 changed files with 461 additions and 476 deletions

View File

@ -90,21 +90,23 @@ static bool setErr(const char *q, yap_error_descriptor_t *i, Term t) {
return i->k ? TermTrue : TermFalse; \
}
#define query_key_i(k, ks, q, i) \
if (strcmp(ks, q) == 0) { \
#define query_key_i(k, ks, q, i) if (strcmp(ks, q) == 0) { \
return MkIntegerTerm(i->k); \
}
#define query_key_s(k, ks, q, i) \
if (strcmp(ks, q) == 0) { \
return (i->k && i->k[0] ? MkStringTerm(i->k) : TermNil); \
}
return MkAtomTerm(Yap_LookupAtom(i->k)); }
#define query_key_t(k, ks, q, i) \
if (strcmp(ks, q) == 0) { \
Term t; if((t = Yap_BufferToTerm(i->k, TermNil) ) == 0 ) return TermNil; return t; }
static Term queryErr(const char *q, yap_error_descriptor_t *i) {
query_key_i(errorNo, "errorNo", q, i);
query_key_i(errorClass, "errorClass", q, i);
query_key_s(errorAsText, "errorAsText", q, i);
query_key_s(errorGoal, "errorGoal", q, i);
query_key_t(errorGoal, "errorGoal", q, i);
query_key_s(classAsText, "classAsText", q, i);
query_key_i(errorLine, "errorLine", q, i);
query_key_s(errorFunction, "errorFunction", q, i);
@ -123,7 +125,7 @@ static Term queryErr(const char *q, yap_error_descriptor_t *i) {
query_key_s(prologParserText, "prologParserText", q, i);
query_key_s(prologParserFile, "prologParserFile", q, i);
query_key_b(prologConsulting, "prologConsulting", q, i);
query_key_s(culprit, "culprit", q, i);
query_key_t(culprit, "culprit", q, i);
query_key_s(errorMsg, "errorMsg", q, i);
query_key_i(errorMsgLen, "errorMsgLen", q, i);
return TermNil;
@ -581,23 +583,17 @@ bool Yap_pushErrorContext(bool pass, yap_error_descriptor_t *new_error) {
/* if (Yap_HasException()) */
/* memset(LOCAL_ActiveError, 0, sizeof(*LOCAL_ActiveError)); */
/* LOCAL_ActiveError->top_error = bf; */
/* } */
yap_error_descriptor_t *Yap_popErrorContext(bool mdnew, bool pass) {
yap_error_descriptor_t *e = LOCAL_ActiveError;
yap_error_descriptor_t *e = LOCAL_ActiveError, *ep = LOCAL_ActiveError->top_error;
// last block
LOCAL_ActiveError = e->top_error;
if (e->errorNo) {
if (!LOCAL_ActiveError->errorNo && pass) {
memmove(LOCAL_ActiveError, e, sizeof(*LOCAL_ActiveError));
} else {
return e;
LOCAL_ActiveError = ep;
if (e->errorNo && !ep->errorNo && pass) {
yap_error_descriptor_t *epp = ep->top_error;
memmove(ep, e, sizeof(*e));
ep->top_error = epp;
}
} else {
if (e->errorNo)
return e;
}
return NULL;
return LOCAL_ActiveError;
}
/**
* Throw an error directly to the error handler

View File

@ -1008,7 +1008,6 @@ Term Yap_read_term(int sno, Term opts, bool clause) {
#endif
yap_error_descriptor_t *new = malloc(sizeof *new);
bool err = Yap_pushErrorContext(true, new);
int lvl = push_text_stack();
parser_state_t state = YAP_START_PARSING;
@ -1051,9 +1050,6 @@ Term Yap_read_term(int sno, Term opts, bool clause) {
#endif /* EMACS */
pop_text_stack(lvl);
Yap_popErrorContext(err, true);
if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
Yap_Error(LOCAL_Error_TYPE, Yap_MkStream(sno), LOCAL_ErrorMessage);
}
return fe.t;
}
}
@ -1521,6 +1517,7 @@ static Int read_term_from_string(USES_REGS1) {
Term t1 = Deref(ARG1), rc;
const unsigned char *s;
size_t len;
BACKUP_H()
if (IsVarTerm(t1)) {
Yap_Error(INSTANTIATION_ERROR, t1, "read_term_from_string/3");
return (FALSE);
@ -1537,6 +1534,7 @@ static Int read_term_from_string(USES_REGS1) {
GLOBAL_Stream[sno].status |= CloseOnException_Stream_f;
rc = Yap_read_term(sno, Deref(ARG3), 3);
Yap_CloseStream(sno);
RECOVER_H();
if (!rc)
return false;
return Yap_unify(rc, ARG2);

View File

@ -29,7 +29,6 @@ add_definitions(-DSQLITE_ENABLE_JSON1=1 )
add_definitions(-DSQLITE_ENABLE_RBU=1 )
add_definitions(-DSQLITE_ENABLE_RTREE=1 )
add_definitions(-DSQLITE_ENABLE_FTS5=1 )
SET_PROPERTY(DIRECTORY PROPERTY COMPILE_DEFINITIONS YAP_KERNEL=1 )
@ -47,6 +46,8 @@ else()
add_library( YAPsqlite3 SHARED
${YAPSQLITE3_SOURCES})
target_link_libraries(YAPsqlite3 libYap )
set_target_properties(YAPsqlite3
PROPERTIES
# RPATH ${libdir} VERSION ${LIBYAPTAI_FULL_VERSION}

View File

@ -198,8 +198,7 @@ compose_message( halt, _Level) --> !,
% syntax error.
compose_message(error(E, Exc), Level) -->
{ '$show_consult_level'(LC), '$print_exception'(Exc)
},
{ '$show_consult_level'(LC) },
location(error(E, Exc), Level, LC),
main_message(error(E,Exc) , Level, LC ),
c_goal( error(E, Exc), Level ),
@ -257,6 +256,7 @@ location(style_check(A,LN,FileName,B ), Level , LC) -->
display_consulting( FileName, Level,style_check(A,LN,FileName,B ), LC ),
[ '~a:~d:0 ~a ' - [FileName,LN,Level] ] .
location( error(_,Info), Level, LC ) -->
{ '$error_descriptor'(Info, Desc) },
{
'$query_exception'(prologPredFile, Desc, File),
@ -267,19 +267,7 @@ location( error(_,Info), Level, LC ) -->
},
!,
display_consulting( File, Level, Info, LC ),
[ '~s:~d:0 ~a in ~s:~s/~d:'-[File, FilePos,Level,M,Na,Ar] ].
location( error(_,Info), Level, LC ) -->
{ '$error_descriptor'(Info, Desc) },
{
'$query_exception'(prologPredFile, Desc, File),
'$query_exception'(prologPredLine, Desc, FilePos),
'$query_exception'(prologPredModule, Desc, M),
'$query_exception'(prologPredName, Desc, Na),
'$query_exception'(prologPredArity, Desc, Ar)
},
!,
display_consulting( File, Level, Info, LC ),
[ '~s:~d:0 ~a in ~s:~s/~d:'-[File, FilePos,Level,M,Na,Ar] ].
[ '~a:~d:0 ~a in ~a:~a/~d:'-[File, FilePos,Level,M,Na,Ar] ].
location( error(_,Info), Level, LC ) -->
{ '$error_descriptor'(Info, Desc) },
{
@ -289,7 +277,7 @@ location( error(_,Info), Level, LC ) -->
},
!,
display_consulting( File, Level, Info, LC ),
[ '~s:~d:0 ~a in ~s():'-[File, FilePos,Level,F] ].
[ '~a:~d:0 ~a in ~a():'-[File, FilePos,Level,F] ].
location( _Ball, _Level, _LC ) --> [].
@ -393,7 +381,7 @@ caller( Info, _) -->
},
!,
[nl],
['~*| raised from ~a:~q:~d, ~a:~d:0: '-[10,M,Na,Ar,File, FilePos]],
['~*| ~q:~d:0 ~a:~q'-[10,File, FilePos,M,Na,Ar]],
[nl].
caller( _, _) -->
[].
@ -982,8 +970,9 @@ confusing to YAP (who will process the error?). So we write this small
stub to ensure everything os ok
*/
:- dynamic in/0.
/*
/*:- dynamic in/0.
prolog:print_message(Severity, Msg) :-
\+ in,
assert(in),
@ -991,7 +980,7 @@ prolog:print_message(Severity, Msg) :-
( prolog:print_message(Severity, Msg), fail;
stop_low_level_trace,
retract(in)
).*/
).
*/
prolog:print_message(Severity, Msg) :-
(
@ -1044,6 +1033,7 @@ prolog:print_message(Severity, Term) :-
!.
prolog:print_message(Severity, Term) :-
translate_message( Term, Severity, Lines0, [ end(Id)]),
writeln(Lines0),
Lines = [begin(Severity, Id)| Lines0],
(
user:message_hook(Term, Severity, Lines)
@ -1057,7 +1047,7 @@ prolog:print_message(Severity, Term) :-
prolog:print_message(_Severity, _Term) :-
format(user_error,'failed to print ~w: ~w~n' ,[ _Severity, _Term]).
'$error_descriptor'( error(_,Info), Info ).
'$error_descriptor'( exception(Info), Info ).
/**