Open dizzzz opened 2 months ago
@dizzzz The error description is correct:
No template function found for call app:test2
Perhaps it could go further in explaining that in order to be a valid "template function", a function referenced in a template must have at least the 2 required parameters: $node as node(), $model as map(*)
. Or, as the comment in app.xqm
states:
(:~
: This is a sample templating function. It will be called by the templating module if
: it encounters an HTML element with an attribute: data-template="app:test" or class="app:test" (deprecated).
: The function has to take 2 default parameters. Additional parameters are automatically mapped to
: any matching request or function parameter.
:
: @param $node the HTML node with the attribute which triggered this call
: @param $model a map containing arbitrary data - used to pass information between template calls
:)
... the key phrase here being:
The function has to take 2 default parameters.
... i.e., the 2 @param
entries listed in the xqdoc.
So the cause of the error is that an element in index.html, <div data-template="app:test2"/>
, causes the templating library to look for a function (a) named app:test2
and (b) bearing the 2 required parameters. When the templating library failed to find such a function, it threw the error. (The app.xqm
library does contain a function app:test2
, but this function doesn't have the 2 required parameters.
Would a fuller description along these lines have helped you debug the issue? Or did you have something different in mind?
Perhaps just remove the need for the function to take 2+ arguments. If the user doesn't need the templating context information, it doesn't make sense to force it on them IMHO.
Isn't this part of the error message Max arity of 20 has been exceeded in searching for this template function. If needed, adjust $templates:MAX_ARITY in the templates.xql module.
now actually wrong? If I recall we switched from using some proprietary eXist-db function to resolve functions, to using the standard fn:function-lookup
(which doesn't have a limit on arity).
@dizzzz When you have a chance could you add a test that demonstrates the issue?
The following short example (app.xqm) shows the problem:
Issue happen when the arity/type of functions (parameters, return values) do not match the expectations of the caller.
Expected behavior
An readable error/showing what the problem is.
Actual behavior
An unusable generic trace:
Reproduction steps
see attached xar file
Please provide the following