# Library(prolog\_coverage) - would like to see into call/1 when used, e.g. catch/3

**URL:** <https://swi-prolog.discourse.group/t/library-prolog-coverage-would-like-to-see-into-call-1-when-used-e-g-catch-3/9421>\
**Category:** General\
**Created:** [December 7, 2025, 9:37pm UTC](https://swi-prolog.discourse.group/t/library-prolog-coverage-would-like-to-see-into-call-1-when-used-e-g-catch-3/9421 "2025-12-07T21:37:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [December 7, 2025, 9:37pm UTC](https://swi-prolog.discourse.group/t/library-prolog-coverage-would-like-to-see-into-call-1-when-used-e-g-catch-3/9421/1 "2025-12-07T21:37:37Z")

</div>

$ swipl --version  
SWI-Prolog version 10.0.0 for x64-win64

Currently using [library(prolog\_coverage)](https://www.swi-prolog.org/pldoc/man?section=prologcoverage).

For predicates like catch/3, which reference call/1 in their documentation (with the [reality](https://www.swi-prolog.org/pldoc/doc/_SWI_/boot/init.pl?show=src#catch/3) not being so apparent), the coverage report doesn’t capture the details of how call/1 is used. I realize this may be difficult—or even impossible—to implement, so I’m wondering if there might be a way to simulate such behavior to test both success and failure cases during testing.

Actual report

```prolog
  341 ++15 catch(
  342 ( find_prolog_files('fixtures', Files),
  343 is_list(Files)
  344 ),
  345 _,
  346 true
  347 ).

```

Something like the following is desired.

```prolog
  341 ++15 catch(
  342 ++15 ( find_prolog_files('fixtures', Files),
  343 ++12 is_list(Files)
  344 ),
  345 _,
  346 ++3 true
  347 ).

```

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [December 8, 2025, 8:54am UTC](https://swi-prolog.discourse.group/t/library-prolog-coverage-would-like-to-see-into-call-1-when-used-e-g-catch-3/9421/2 "2025-12-08T08:54:47Z")

</div>

The success of the catch/3 basically confirms the success of what it calls 🙂 But no, at the moment there is no proper position support for meta-calling. Would be nice to have as it would also improve the debugger. Not easy to implement though ☹

For good debugging support I advice to avoid complex meta-calls, i.e., use a helper predicate. This is also faster. The system can be asked to do this transformation automatically, but this too looses source location information. Maybe there is a solution there by faking the source location information of the generated clause to reflect the positions from the meta-call …

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [December 9, 2025, 5:20pm UTC](https://swi-prolog.discourse.group/t/library-prolog-coverage-would-like-to-see-into-call-1-when-used-e-g-catch-3/9421/3 "2025-12-09T17:20:10Z")

</div>

This is a step in the right direction, at least for my need.

```prolog
  123 %% persist_assert_pred_def(+Name, +Arity, +Module, +File, +Line)
  124 % Safely persists pred_def with duplicate detection and error handling
  125 % persist_assert_pred_def(Name, Arity, Module, File, Line) :-
  126 % catch(
  127 % ( % Check if already exists (duplicate detection)
  128 % ( pred_def(Name, Arity, Module, File, Line)
  129 % -> % Already exists - log warning and succeed
  130 % log_warning(debug_kb_consistency,
  131 % duplicate_found(pred_def(Name, Arity, Module, File, Line)))
  132 % ; % Not a duplicate - proceed with assertion
  133 % % Log the intent to assert
  134 % log_debug(debug_kb_assert,
  135 % pred_def(Name, Arity, Module, File, Line)),
  136 % % Use auto-generated persist predicate
  137 % assert_pred_def(Name, Arity, Module, File, Line)
  138 % )
  139 % ),
  140 % Error,
  141 % % Log failure and re-throw
  142 % ( log_error(debug_kb_assert,
  143 % operation_failed(pred_def(Name, Arity, Module, File, Line), Error)),
  144 % throw(Error)
  145 % )
  146 % ).
  147                    
  148 ++55,870 persist_assert_pred_def(Name, Arity, Module, File, Line) :-
  149 ++55,870 catch(
  150 goal_a_success(Name, Arity, Module, File, Line),
  151 Error,        
  152 goal_a_failure(Name, Arity, Module, File, Line, Error)
  153 ).
  154                    
  155 ++55,870 goal_a_success(Name, Arity, Module, File, Line) :-
  156 ( % Check if already exists (duplicate detection)
  157 +20-55,850 ( pred_def(Name, Arity, Module, File, Line)
  158 -> % Already exists - log warning and succeed
  159 ++20 log_warning(debug_kb_consistency,
  160 duplicate_found(pred_def(Name, Arity, Module, File, Line)))
  161 ; % Not a duplicate - proceed with assertion
  162 % Log the intent to assert
  163 ++55,850 log_debug(debug_kb_assert,
  164 pred_def(Name, Arity, Module, File, Line)),
  165 % Use auto-generated persist predicate
  166 ++55,850 assert_pred_def(Name, Arity, Module, File, Line)
  167 )
  168 ).
  169                    
  170 ### goal_a_failure(Name, Arity, Module, File, Line, Error) :-
  171 % Log failure and re-throw
  172 ( log_error(debug_kb_assert,
  173 operation_failed(pred_def(Name, Arity, Module, File, Line), Error)),
  174 throw(Error)
  175 ).

```
