Skip to content

Conversation

@Skgland
Copy link
Contributor

@Skgland Skgland commented Nov 21, 2025

Make errors thrown from rust compatible with call_with_error_context/2 in that the second argument of a thrown error is a list.

This exasperates the problem described in #3171 as now way more list terms are constructed from rust (see updated tests) and as such this PR is blocked on that issue being resolved.

@Skgland
Copy link
Contributor Author

Skgland commented Nov 21, 2025

The (.)/2 list terms are being constructed at

pub(super) fn error_form(&self, mut err: MachineError, predicate: MachineStub) -> MachineStub {
err.add_context(functor!(
atom!("-"),
[atom_as_cell((atom!("predicate"))), functor(predicate)]
));
let mut context = functor!(atom!("[]"));
for ctx in err.context.into_iter().rev() {
context = functor!(atom!("."), [functor(ctx), functor(context)]);
}
functor!(atom!("error"), [functor((err.stub)), functor(context)])
}

load_module_test(
"tests-pl/issue831-call0.pl",
" error(existence_error(procedure,call/0),call/0).\n",
" error(existence_error(procedure,call/0),'.'(predicate-call/0,[])).\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as soon as it works: [predicate-call/0]? (that's the expectation)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the old error that would be my expectation.
Though the error context appears to be rather odd even for the old error.
With the second argument usually being the predicate that encountered an error this would mean that call/0 failed to find call/0 which shouldn't happen as call/0 doesn't exists.
Wherever that error is being thrown the context appears to be off.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The source of this error appears to be

pub(super) fn throw_undefined_error(&mut self, name: Atom, arity: usize) -> MachineStub {
let stub = functor_stub(name, arity);
let err = self.existence_error(ExistenceError::Procedure(name, arity));
self.error_form(err, stub)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In ab34905 I have now removed the predicate context for those errors.
I don't see any useful context being available.
Though it might be worth looking into adding context for goals evaluated as part of an initialization/1 directive i.e. something like [declaration-initialization/1, goal-Goal, file-File, line-Line]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants