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


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


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


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

class AgentStatement(Document):

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

def enqueue_match(self):
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