<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Forex Software — Bug(?): "RangeError: Maximum call stack size exceeded"]]></title>
		<link>https://forexsb.com/forum/topic/9469/bug-rangeerror-maximum-call-stack-size-exceeded/</link>
		<atom:link href="https://forexsb.com/forum/feed/rss/topic/9469/" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Bug(?): "RangeError: Maximum call stack size exceeded".]]></description>
		<lastBuildDate>Fri, 16 Jun 2023 19:16:04 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Bug(?): "RangeError: Maximum call stack size exceeded"]]></title>
			<link>https://forexsb.com/forum/post/75310/#p75310</link>
			<description><![CDATA[<p>You are right.</p><p>Node.js executes only a limited count of recursions <img src="https://forexsb.com/forum/img/smilies/sad.png" width="15" height="15" alt="sad" />.</p><p>I&#039;ll upload an update tomorrow.</p>]]></description>
			<author><![CDATA[null@example.com (Popov)]]></author>
			<pubDate>Fri, 16 Jun 2023 19:16:04 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/75310/#p75310</guid>
		</item>
		<item>
			<title><![CDATA[Re: Bug(?): "RangeError: Maximum call stack size exceeded"]]></title>
			<link>https://forexsb.com/forum/post/75264/#p75264</link>
			<description><![CDATA[<p>After re-coding the &quot;addSuffixToJsonFile&quot; function that causes the stack overflow from:</p><div class="codebox"><pre><code>function addSuffixToJsonFile(colPath) {
    if (!existsSync(colPath)) {
        return colPath;
    }

    const match = colPath.match(/\((\d+)\).json$/);
    if (match) {
        const index   = Number(match[1]);
        const newPath = colPath.replace(`(${index})`, `(${index + 1})`);
        return addSuffixToJsonFile(newPath);
    }

    const newPath = colPath.replace(&quot;.json&quot;, &quot;_(1).json&quot;);
    return addSuffixToJsonFile(newPath);
}</code></pre></div><p>to</p><div class="codebox"><pre><code>function addSuffixToJsonFile(colPath) {
    // RegExp that matches the last number before the &quot;.json&quot; extension, with and without the index in parentheses
    var regex = /(?:_(\d+)(?:_\((\d+)\))?)?\.json$/;
    var newPath = colPath;

    // Check if the initial file exists
    if (!existsSync(newPath)) {
        return newPath;
    }

    // Loop until a non-existent file path is found
    while (existsSync(newPath)) {
        // Use the replace function with a callback to generate the new file path
        newPath = newPath.replace(regex, function (_, baseIndex, suffixIndex) {
            // If a suffix index is found, increment it by 1, otherwise set it to 1
            var newIndex = suffixIndex ? parseInt(suffixIndex, 10) + 1 : 1;
            // Return a new file path with the updated index in parentheses and the base index unchanged
            return &#039;_&#039; + baseIndex + &#039;_(&#039; + newIndex + &#039;).json&#039;;
        });
    }

    // Return the non-existent file path
    return newPath;
}</code></pre></div><p>The error has gone away. Reason: The error occurred because the function addSuffixToJsonFile used recursion to find a suitable file name, which caused a stack overflow for large numbers like in my case with 5000+ files in the directory. To fix this issue, I have converted the recursion to a loop, which will avoid the stack overflow issue.</p>]]></description>
			<author><![CDATA[null@example.com (geektrader)]]></author>
			<pubDate>Thu, 15 Jun 2023 06:37:29 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/75264/#p75264</guid>
		</item>
		<item>
			<title><![CDATA[Bug(?): "RangeError: Maximum call stack size exceeded"]]></title>
			<link>https://forexsb.com/forum/post/75263/#p75263</link>
			<description><![CDATA[<p>Hi Mr. Popov,</p><p>with EG 2.34 I am regularly getting this error:</p><div class="codebox"><pre><code>                        ..:: Express Generator v2.34 ::..

    Market : Unknown GBPJPY H1
    From   : 1986-12-19 14:00, To: 2017-03-21 00:00, Bars: 189249
    Spread : 12, Swap long: 15, Swap short: -17.2, Commission: 11 USD
    Account: 100000 USD, Leverage: 500, Entry: 1 lots

Generator started...

  - Ascended: 5, Calculated: 15279, Opt: 5, Time: 18:00, Coll: 5
Collection exported: ./collections/Unknown_GBPJPY_H1_2017-03-21_str_5_(5172).json

  - Ascended: 10, Calculated: 30019, Opt: 10, Time: 30:54, Coll: 5
Collection exported: ./collections/Unknown_GBPJPY_H1_2017-03-21_str_5_(5195).json

RangeError: Maximum call stack size exceeded, Time: 51:45, Coll: 5
    at existsSync (node:fs:300:1)
    at addSuffixToJsonFile (C:\PortablePrograms\ExpressGenerator\bin\lib\collection.js:321:10)
    at addSuffixToJsonFile (C:\PortablePrograms\ExpressGenerator\bin\lib\collection.js:329:16)
    at addSuffixToJsonFile (C:\PortablePrograms\ExpressGenerator\bin\lib\collection.js:329:16)
    at addSuffixToJsonFile (C:\PortablePrograms\ExpressGenerator\bin\lib\collection.js:329:16)
    at addSuffixToJsonFile (C:\PortablePrograms\ExpressGenerator\bin\lib\collection.js:329:16)
    at addSuffixToJsonFile (C:\PortablePrograms\ExpressGenerator\bin\lib\collection.js:329:16)
    at addSuffixToJsonFile (C:\PortablePrograms\ExpressGenerator\bin\lib\collection.js:329:16)
    at addSuffixToJsonFile (C:\PortablePrograms\ExpressGenerator\bin\lib\collection.js:329:16)
    at addSuffixToJsonFile (C:\PortablePrograms\ExpressGenerator\bin\lib\collection.js:329:16)</code></pre></div><p>I think it happens if there are a lot of collection files in the destination directory already (5000+) and it has to cycle through a loop to find the next free number. This can happen if EG runs for a long time and I hope you can fix it to still be able to handle that amount of files (and much more if its running unattended for weeks).</p><p>Please also see <a href="https://stackoverflow.com/questions/20936486/node-js-maximum-call-stack-size-exceeded">https://stackoverflow.com/questions/209 … e-exceeded</a> (in case it helps anything).</p><p>Thanks for the fix in advance.</p>]]></description>
			<author><![CDATA[null@example.com (geektrader)]]></author>
			<pubDate>Thu, 15 Jun 2023 05:59:16 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/75263/#p75263</guid>
		</item>
	</channel>
</rss>
