Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message when evaluating a query AST #509

Open
JosVerburg opened this issue Jul 11, 2022 · 1 comment
Open

Improve error message when evaluating a query AST #509

JosVerburg opened this issue Jul 11, 2022 · 1 comment

Comments

@JosVerburg
Copy link
Member

When we evaluate a query AST we don't get as good error messaging as with normal string queries.

I've reproduced this in the ./demo/main.ts by changing the runNormalXPath to

async function runNormalXPath(script: string, asXQuery: boolean) {
	const queryAst = fontoxpath.parseScript(
		script,
		{
			language: fontoxpath.Language.XQUERY_3_1_LANGUAGE,
			debug: false,
		},
		new Document()
	);

	const raw = [];
	const it = fontoxpath.evaluateXPathToAsyncIterator(queryAst, xmlDoc, null, null, {
		debug: true,
		disableCache: true,
		language: asXQuery
			? fontoxpath.evaluateXPath.XQUERY_3_1_LANGUAGE
			: fontoxpath.evaluateXPath.XPATH_3_1_LANGUAGE,
		logger: {
			trace: (m) => {
				traceOutput.textContent = m;
				console.log(m);
			},
		},
	});
	...

I know that I do set the debug flag to false when building the AST, but the evaluate function throws an invalid array length error when I set it to true instead.

Using this, when I execute the following XQuery if ((1, 2)) then '(^∀^●)ノシ' else '╰(‵□′)╯' I get the following error message

FORG0006: A wrong argument type was specified in a function call.

While I was expecting the error message as I would get it when treating the query as a string (pass the script to evaluateXPathToAsyncIterator instead of queryAst)

1: if ((1, 2)) then '(^∀^●)ノシ' else '╰(‵□′)╯'
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2: 

Error: FORG0006: A wrong argument type was specified in a function call.
  at <ifThenElseExpr>:1:1 - 1:43
@DrRataplan
Copy link
Collaborator

I think we should just document that we place the query in a comment at the start of the AST (or at least we do in Fonto; just do it in FontoXPath instead). From there we can make harder assumptions it's there and print it in the error.

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

No branches or pull requests

2 participants