Skip to content

Commit ace10bb

Browse files
jjtoltonclaude
andcommitted
Improve syntax error reporting by adding file context
When syntax errors occur during file loading, the error messages now include the source file name through call_with_error_context/2 as recommended in issue #302. Before: error(syntax_error(incomplete_reduction),read_term/3:8). After: error(syntax_error(incomplete_reduction),[file-'test_file.pl'|read_term/3:8]). This approach uses the existing call_with_error_context/2 mechanism instead of modifying the core error struct, following the established pattern for enhancing error context in Scryer Prolog. Changes: - Modified stream_next_term/4 in src/loader.pl to wrap read_term/3 calls with call_with_error_context/2, providing file context when available Resolves: #302 Related: #3133 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent e4d9692 commit ace10bb

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/loader.pl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,14 @@
201201

202202
stream_next_term(Stream, Term, LinesRead, Singletons) :-
203203
( '$devour_whitespace'(Stream) ->
204-
stream_property(Stream, position(position_and_lines_read(_, LinesRead))),
205-
read_term(Stream, Term, [singletons(Singletons)])
204+
stream_property(Stream, position(position_and_lines_read(Pos0, LinesRead))),
205+
( prolog_load_context(file, File) ->
206+
call_with_error_context(
207+
read_term(Stream, Term, [singletons(Singletons)]),
208+
file-File
209+
)
210+
; read_term(Stream, Term, [singletons(Singletons)])
211+
)
206212
; Term = end_of_file
207213
).
208214

0 commit comments

Comments
 (0)