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

fn:stack-trace: keep, drop, replace with $err:stack-trace ? #689

Open
ChristianGruen opened this issue Sep 8, 2023 · 6 comments
Open

fn:stack-trace: keep, drop, replace with $err:stack-trace ? #689

ChristianGruen opened this issue Sep 8, 2023 · 6 comments
Labels
PRG-easy Categorized as "easy" at the Prague f2f, 2024 PRG-required Categorized as "required for 4.0" at the Prague f2f, 2024 Propose for V4.0 The WG should consider this item critical to 4.0 XQFO An issue related to Functions and Operators

Comments

@ChristianGruen
Copy link
Contributor

The current specification contains a diagnostic function called fn:stack-trace. Many other languages provide a similar function: The returned output can possibly help to understand which function calls led to an error during the evaluation of a code.

Still, I have strong doubts that it is a good decision to include this function in the standard:

The specification gives you a vast amount of freedom how to implement and optimize things. As a result, it’s completely feasible and reasonable to rewrite the following code…

declare function local:double($f) {
  $f * 2
};
(1 to 6) ! local:double(.)

…to (1 to 6) ! (. * 2) at compile time. If a user adds a fn:stack-overflow call in the function body, s·he would expect to find the function invocation of the original code representation in the output. As always, there are technical solutions to achieve this (store additional information in the evaluation tree on the original query; suppress optimizations when fn:stack-trace is found), but all of them can affect the runtime behavior and lead to different evaluation trees, hiding possible bugs in the implementation (which can be a reason to call fn:stack-trace at all).

A standard should provide a minimum amount of assurance that a function behaves similarly across different implementations. At this time, I don’t believe we can’t give that guarantee.

Related: #55, #686

– As an alternative, a stack trace could optionally be created by an implementation when an error is triggered.

@ChristianGruen ChristianGruen added XQFO An issue related to Functions and Operators Editorial Minor typos, wording clarifications, example fixes, etc. labels Sep 8, 2023
@Arithmeticus
Copy link
Contributor

I doubt that I am representative of the type of person who should influence this question. That said, if fn:stack-trace were made available, I would use it relatively often, certainly in development work and possibly in production.

@ChristianGruen
Copy link
Contributor Author

@Arithmeticus Thanks. Out of interest: What would be productive use cases for the function? Would it be beneficial or limiting for you to have the stack trace generated by errors instead?

@Arithmeticus
Copy link
Contributor

I have had to develop applications in environments where it is difficult (sometimes very difficult) to intercept the message listener when invoking an XSLT subprocess, and the ability to write in XSLT the stack trace to a secondary result document (<xsl:result-document>) would be useful. It's hard for me to say further, because I don't know what the output of fn:stack-trace would be, and it's only by playing around with it that I can discern other ways it might be used.

The option with errors would be a benefit. That is, bundling as an available variable within e.g. <xsl:catch>? Seems to make more sense.

@ChristianGruen ChristianGruen added the Propose for V4.0 The WG should consider this item critical to 4.0 label Oct 25, 2023
@ChristianGruen
Copy link
Contributor Author

To revive this discussion:

One pragmatic suggestion could be to replace fn:stack-trace with an $err:stack-trace variable in the catch clause (and a corresponding $err:map entry).

In general, when we add features to the standard, I think our rule of thumb should be that there will be at least two implementations that support it.

@ChristianGruen ChristianGruen changed the title fn:stack-trace: keep or drop? fn:stack-trace: keep, drop, replace with $err:stack-trace ? Jan 15, 2024
@rhdunn
Copy link
Contributor

rhdunn commented Feb 7, 2024

For reference, MarkLogic includes a stack trace as part of the error XML data in its catch block.

I've also just found that Oracle has a get-stack-trace method that returns a stack trace in a catch block, or empty sequence outside of the catch block. [1]

So there is existing support for this behaviour, just not via a standardized API/structure. Note that both MarkLogic and Oracle provide the stack trace as XML.

[1] https://docs.oracle.com/cd/E29584_01/webhelp/XQueryDev/src/rxqd_eutil_get-stack-trace.html

@ndw
Copy link
Contributor

ndw commented Jun 4, 2024

Consensus of the folks present in Prague: provide a stack trace in errors, but not as a stand alone function.

@ndw ndw added PRG-easy Categorized as "easy" at the Prague f2f, 2024 PRG-required Categorized as "required for 4.0" at the Prague f2f, 2024 and removed Editorial Minor typos, wording clarifications, example fixes, etc. labels Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PRG-easy Categorized as "easy" at the Prague f2f, 2024 PRG-required Categorized as "required for 4.0" at the Prague f2f, 2024 Propose for V4.0 The WG should consider this item critical to 4.0 XQFO An issue related to Functions and Operators
Projects
None yet
Development

No branches or pull requests

4 participants