However, when there are runtime errors it only reports the error, but not the code that produced it.
Sorry, I need more information. The following query...
declare %rest:path('invalid') function local:err() { 1 + <a/> };
...results in the following runtime error:
Stopped at (...path to webapp...), 2/6: [FORG0001] Cannot cast to xs:double: "".
Stack Trace: - (...path to webapp...), 1/40