WebAssembly build throws instead of returning an error Prolog term
Description
When using the WebAssembly build, making a query that results in an error like error(existence_error(procedure,foo/1),foo/1) currently causes the engine to throw an exception instead of returning a Prolog term. In think the behavior is wrong, because in Prolog, errors are represented as normal terms.
How to Reproduce
import initScryer, { MachineBuilder } from "./pkg/scryer_prolog.js";
const wasm = await fetch("./pkg/scryer_prolog_bg.wasm");
const module = await WebAssembly.compile(await wasm.arrayBuffer());
await initScryer(module);
const machine = new MachineBuilder().build();
const query = "foo(X).";
const answers = machine.runQuery(query);
Currently, this throws:
Uncaught Error: Prolog error
Related to guregu/scryer-js#10
The plan here was to eventually give access to the error term in the exception, so that you can catch it. There is no support for this in the Rust side yet, so it needs to be done there before.
Do you think this shouldn't throw an error at all in the Javascript side? I did it like this to preserve the semantics of errors, but maybe they should be returned like exceptions. On the other hand, maybe we should throw exceptions too.
Note: Errors in Prolog are just exceptions with a specific format
I personally don't like libraries that throw exceptions, but I realize that's not a strong enough reason by itself to avoid doing it. That said, to recover from an exception right now, you have to rebuild the Machine, which I think is not ideal (also considering that you need to build again your knowledge base). For me, since Prolog errors are just terms we can reason about, I believe nothing special should happen, the error should simply be returned as a regular term. This way, the application user can decide how to handle it based on their specific use case. Returning the exception without throwing would also be a good solution, I think. But, I personally would prefer if it was simply a term.