Testing and debugging Shopify Scripts

You can use the debugging features in the Script Editor to test and debug your scripts.

The Script Editor will check your code for basic errors while you're writing a script:

Error reporting in the Script Editor

It will also report errors that occur in published scripts, and it will send you an email when these errors occur:

Screenshot of errors published scripts in the Script Editor

It's a good idea to correct errors, such as errors in syntax, before you test or publish a script. If your script has syntax errors, then testing your script probably won't work.

If you need more information on a script error, then hover over the red x icon in the Script Editor's margin:

Hovering over the X in the Script Editor margin reveals details about syntax errors

Duplicating scripts

If you need to test or debug a published script because it contains errors, then duplicate the script and publish the duplicate script. You want to debug the script that was published when the error occurred because this version has the error details attached to it.

Production error details that are attached to a script are not copied when you duplicate a script.

To duplicate a script:

  1. In the Script Editor, click the name of the script that you want to duplicate.

  2. Click Duplicate to make a copy of the script.

Debug production errors

To debug a production error:

  1. Duplicate the script that contains the errors.

  2. Publish the duplicate script so that there is a version of the script that is available to your customers in your online store. This step assumes that the script doesn't include so many errors that it needs to be unpublished (removed) from your online store.

  3. Debug the original script using the error details that are attached to it.

Test a script

While you are working on a script, you can test it from within the Script Editor to make sure it works before you publish it for your online store.

To test a script:

  1. In the Script Editor, open the script that you want to test.

  2. To edit a test cart, click Input. You can also click Both to see the script code and the test cart at the same time:

    Click 'Input' in the Script Editor

    The input view shows options for editing a cart to test your script. You can add products, customers, discount codes, customer information, and shipping information based on what you want to test your script against.

    • Type in the Products section to search for and add products to the test order.
    • Type in the Discount code section to search for and add discount codes to the test order.
    • Type in the Customer information section to search for and add customers to the test order.
    • Click Add or Edit in the Shipping address section to change the shipping address for the test order.
  3. Click Run script to see the changes that the script makes to your test cart:

    If your script runs successfully, then the Output section will update to show the changes applied by the script. If the Output section doesn't change, or there are unexpected changes, then there might be errors in your script. Check the Console box in the Ruby source code section to resolve any script errors:

    The Console box will report the script's resource usage. More complex scripts will use more resources. Scripts have a limited amount of CPU and memory available to them.

  4. When you are finished:

    • click Save draft to update and save an unpublished draft of the script
    • click Enable to update and publish the script.

Unsubscribe from error notifications

When you publish a script, you are subscribed automatically to notification emails for that script. Whenever a production error occurs in that script, you receive an email about the error. You can then open the Script Editor to find out more information about the error and debug it.

You can unsubscribe from these emails after you've received one. To unsubscribe, open the Production Error page for the error and click Unsubscribe:

Unsubscribe from error notifications

Next steps

After you are satisfied with a your script, you can publish it to your online store. You can also update update your Liquid template files so that your online store will respond to the changes that your scripts make.

Learn more

Learn more about:

Ready to start selling with Shopify?

Try it free