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

Error on stack exhaustion contains massive Node backtrace in .message element #630

Open
rrthomas opened this issue Mar 25, 2024 · 5 comments

Comments

@rrthomas
Copy link
Contributor

When I cause fontoxpath to exhaust the Node.js stack (not fontoxpath's fault!), the error returned to my code contains the Node backtrace in the .message element. I wish it did not, as there's no easy way for me to avoid printing it while still printing the actual error (which would contain a long XQuery backtrace: not great, but still, at least that's the fault of my code!).

I am running with debug: false.

@rrthomas
Copy link
Contributor Author

To put the problem another way, I get the same voluminous output if I console.log(error.message) as if I console.log(error).

@DrRataplan
Copy link
Collaborator

DrRataplan commented Apr 2, 2024

Hey Reuben,

Oof, that sounds annoying. How would you repro this? is it something like this?

var fontoxpath = require("fontoxpath")

try {
fontoxpath.evaluateXPathToString('(1 to 100000)!(. to 100000) => sum()')
} catch (e) {
console.log('ERROR', e);
}

or are custom functions involved?

@rrthomas
Copy link
Contributor Author

rrthomas commented Apr 2, 2024

In my case it used a custom function, but I think a function that always recurses would do it. I'll look when I have a moment!

@rrthomas
Copy link
Contributor Author

rrthomas commented Apr 3, 2024

The example you give results in Node.js heap exhaustion, not XQuery stack exhaustion. That causes Node.js itself to crash; not a lot you can do here!

Here's an example that gives a short (if still unhelpful) backtrace, with a user-defined function:

import fontoxpath from 'fontoxpath'

try {
  fontoxpath.evaluateXPathToString(`
  declare function local:foo() {
    local:foo()
  };
  local:foo()
  `, undefined, undefined, undefined, {language: fontoxpath.evaluateXPath.XQUERY_3_1_LANGUAGE})
} catch (e) {
  console.log('ERROR', e);
}

@rrthomas
Copy link
Contributor Author

rrthomas commented Apr 3, 2024

I suspect that the long node backtrace requires a custom function implemented in JavaScript.

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