Suddenly got production error TimeQuotaExceeded

Shopify Partner
5 0 0

I have a bulk discount script which runs fine, but the store got two production errors TimeQuoteExceeded at unexpected time and I don't know how. Please help me to scan through the script to determine which line might be a potential issue.

The script was published: Nov 28, 2017
The error happened the first time: Dec 21, 2017
The error happened the second time: Feb 14, 2018

I had contacted Shopify for support after it happened the first time and they replied that could be a glitch and unlikely to happen again, but it did, so I cannot just say (to the client) that the glitch happened again.

# If the customer orders 3 or more, a discount of 5% is given.
# If the customer orders 5 or more, a discount of 7% is given.
# If the customer orders 10 or more, a discount of 10% is given.

# 12274466820: skystream-two-streaming-media-player
# 15519547320: skystream-two-air-mouse-package
# 358654672920: skystream-two-cord-cutting-package
@streamingMediaPlayer = 12274466820
@airMousePackage = 15519547320
@cordCuttingPackage = 358654672920

  10 => 10,
  5 => 7,
  3 => 5,
Input.cart.line_items.each do |line_item|
  next if line_item.variant.product.gift_card?
  next if ( != @streamingMediaPlayer && != @airMousePackage && != @cordCuttingPackage)
  quantity, discount = DISCOUNTS_BY_QUANTITY.find do |quantity, _|
    line_item.quantity >= quantity
  next unless discount

  message = "#{discount}% off with buying at least #{quantity}."
    line_item.line_price * ( - discount.to_d / 100),
    message: message,

Output.cart = Input.cart

And here is the response from Shopify when it happened the first time:

I believe this time quota error is shown whenever the script takes longer than 100 ms to execute during a cart checkout process. Generally speaking, this would occur when there are lots of items in the cart since the script has to run code for each of those items in the cart.

The best way to avoid this in the future is to reduce the number of actions a script needs to perform per loop of cart items. Besides this, there is not a lot that can be done.

However, the good news is that because your script is fairly short and it seems to have been just a one-off error, it was probably just a glitch that is unlikely to happen again.


Shopify Expert
10037 119 1873

The first line in the response from Shopify is important for you to consider. The memory/time usage will Nth scale for each line item you have in the cart. 

Review orders where it failed. Did those orders have lots of items in the cart? Nth scaling is something to look out for, and will always break Scripts at some point. You can do some testing by throwing a varied array of line items into the cart and see the results in the Script editor.

Now if this failed on orders with only a few (or even 1) item in the cart something else is going on. 

★ Winning Partner of the Build a Business competition. ★
Shopify Partner
5 0 0

Thanks Jason, surprisingly that the carts which caused the issue only have one item at that time so I guess the issue is somewhere else.

New Member
1 0 0

Hi Gin,

 I'm facing the same issue, did you come around any solution for this?

Shopify Partner
5 0 0


Nope, after emailing back and forth, Shopify said that they will keep looking into that and told us to report them if this issue occured again. Until now, this issue hasn't happened again so I guess that was Shopify's bug or system downtime.

Shopify Partner
5 0 0

One more thing, my client had refused to pay even a dollar for my effort to build to whole website, and reset all my credentials to the store so I haven't had a chance to track their system anymore.

Shopify Expert
67 0 3

We just saw this popup on a site thats been running the same script without issue for some time. One thing we do know is this was a very high traffic day; 250K sessions w/ 50K to one product. I suspect it's nothing to do with the script itself but the servers being able to handle the load. 

Not sure that helps but that's my theory.