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:
It will also report errors that occur in published scripts, and it will send you an email when these errors occur:
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:
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:
In the Script Editor, click the name of the script that you want to duplicate.
Click Duplicate to make a copy of the script.
Debug production errors
To debug a production error:
Duplicate the script that contains the errors.
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.
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:
In the Script Editor, open the script that you want to test.
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:
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.
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.
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:
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 about: