html-to-text / node-html-to-text

Advanced html to text converter
Other
1.59k stars 224 forks source link

Maximum call stack size exceeded RangeError: Maximum call stack size exceeded #315

Open xhaferd opened 3 months ago

xhaferd commented 3 months ago

I am using this library within a lambda function to convert email contents to plain text, since Microsoft Graph API returns them in HTML format. In one execution it processes about 20-30 emails in parallel.

I am getting the following error:

ERROR   Maximum call stack size exceeded RangeError: Maximum call stack size exceeded
    at Array.flatMap (<anonymous>)
    at /var/task/node_modules/@selderee/plugin-htmlparser2/lib/hp2-builder.cjs:13:38
    at /var/task/node_modules/@selderee/plugin-htmlparser2/lib/hp2-builder.cjs:40:33
    at /var/task/node_modules/@selderee/plugin-htmlparser2/lib/hp2-builder.cjs:13:51
    at Array.flatMap (<anonymous>)
    at Picker.f (/var/task/node_modules/@selderee/plugin-htmlparser2/lib/hp2-builder.cjs:13:38)
    at Picker.pick1 (/var/task/node_modules/selderee/lib/selderee.cjs:426:30)
    at recursiveWalk (/var/task/node_modules/html-to-text/lib/html-to-text.cjs:1241:46)
    at f1 (/var/task/node_modules/html-to-text/lib/html-to-text.cjs:27:44)
    at formatBlock$1 (/var/task/node_modules/html-to-text/lib/html-to-text.cjs:1324:3)

and this is the code:

export const convertHtmlToText = (html: string): string => {
    const text = htmlToText(html, {
        wordwrap: null, // Disable word wrapping
    });
    return text;
}
KillyMXI commented 3 months ago

Usually happens on very badly formed HTML. Like when someone put an unescaped stack trace inside.

Error message tells me very little without the HTML that causes this.

We have some protection against large input, but cloud functions may have even stricter limitations. You may need to adjust limits options to sensible values.