I'm getting "Uncaught (in promise) RangeError: Maximum call stack size exceeded"

Hi,

I’m getting this error when running below scripts. I have triued to enqueue but with the same error.

JS

frappe.ui.form.on(‘Agent Statement’, {
refresh: function(frm) {
},
match: function(frm) {
frappe.call({
method: “enqueue_match”,
args: {self: frm},
callback(r) {
if(r.message) {
//
}
}
});
}
});

Python

from future import unicode_literals
import frappe
from frappe.model.document import Document

class AgentStatement(Document):
pass

@frappe.whitelist()
def match_invoices(self):
found = 0
total = 0

for invoice in self.invoices:
inv = frappe.db.sql(“”“SELECT parent from tabOnline Payment Request Invoices
where reference_number = %s”“”, invoice.invoice_no, as_dict=1)
total = total + 1

  if inv:
  	invoice.requested = 1
  	invoice.request_reference = i.parent
  	found = found + 1

return found

@frappe.whitelist()
def enqueue_match(self):
frappe.enqueue(“atndesk.collections.doctype.agent_statement.agent_statement.match_invoice”)
frappe.msgprint(_(“Queued for updating latest price in all Bill of Materials. It may take a few minutes.”))

Please help.

This error is almost always means you have a problem with recursion in JavaScript code, as there isn’t any other way in JavaScript to consume lots of stack. Sometimes calling a recursive function over and over again, causes the browser to send you Maximum call stack size exceeded error message as the memory that can be allocated for your use is not unlimited.

How to fix

Wrap your recursive function call into a -

  • setTimeout
  • setImmediate or
  • process.nextTick

Also, you can localize the issue by setting a breakpoint on RangeError type of exception , and then adjust the code appropriately. Moreover, you can managed to find the point that was causing the error by check the error details in the Chrome dev toolbar console , this will give you the functions in the call stack, and guide you towards the recursion that’s causing the error.

1 Like