pack_errors.pl -- Contextual error handling for packs

This is a simple library for (a) middle management handling of pack errors, (b) provide a simple, uniform way for informing users where the errors come from, and (c) provide a few useful pre-canned errors.

The main aim is to create contextual version of messages that can be used from different packs.

Wrapper errors (each message below is an underlying error) pack_error(Pack,Vrb,Message) when Vrb is false there is no message about the pack the error originated from
pack_error(Pack,Message) as above with Vrb = true

Slowly we adding some generic error handling: see caught/3

?- throw( pack_error(os,ground_at(3,name(_))) ).
ERROR: pack(os): Ground argument expected at position: 3, but name(_G3369) was found
?- throw( pack_error(os,os_pred/3,ground_at(3,name(_))) ).
ERROR: os:os_pred/3: Ground argument expected at position: 3, but name(_G6625) was found
?- throw( ground_at(3,name(_)) ).
ERROR: Ground argument expected at position: 3, but name(_G1021) was found

Prepacked errors:

?- throw( pack_error(mlu,lengths_mismatch(learners,predictions,3,4)) ).
ERROR: pack(mlu): Lists for learners and predictions have mismatching lengths: 3 and 4 respectively
?- throw( pack_error(mlu,k_fold_learn/3,lengths_mismatch(learners,predictions,3,4)) ).
ERROR: mlu:k_fold_learn/3: Lists for learners and predictions have mismatching lengths: 3 and 4 respectively
?- throw( pack_error(os,os_term/2,cast(abc('file.csv'),atom)) ).
ERROR: os:os_term/2: Cannot cast: abc(file.csv), to type: atom

Defining new pack errors.

example file:

:- multifile( pack_errors:message/3 ).

pack_errors:message( fold_data_insufficient(Dlen,N) ) -->
        ['Insufficient length of data (~d) as ~d folds are required'-[Dlen,N]].
pack_errors:message( fold_data_residual(Dlen) ) -->
        ['Residual data of length: ~d while splitting folds'-[Dlen]].

Once the above has been loaded, try with

?- throw( fold_data_insufficient(10,20) ).
ERROR: Insufficient length of data (10) as 20 folds are required
?- throw( pack_error(mlu,fold_data_insufficient(10,20) ) ).
ERROR: pack(mlu): Insufficient length of data (10) as 20 folds are required
?- throw( pack_error(mlu,k_fold_learn/4,fold_data_insufficient(10,20) ) ).
ERROR: mlu:k_fold_learn/4: Insufficient length of data (10) as 20 folds are required
author
- nicos angelopoulos
version
- 0.1 2016/01/30
- 0.2 2016/02/24
To be done
- equal lentth list checking
caught(Goal, Error, Opts)
Call Goal with error capture as failure. On failure, throws packaged Error iff the value of option report(Report) is Report==error. Option report() should exist. The only alternative value is Report==fail.
pack_errors
This is decoy predicate, writing a simple message. Here to provide an anchor for documentation pointers.
pack_errors_version(-Version, -Date)
Current version and reelase date for the library.