Testing and debugging Shopify Scripts
You can use the debugging features in the Script Editor to test and debug your scripts.
The Script Editor checks your code for basic errors while you're writing a script:
It also reports errors that occur in published scripts, and it sends 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 doesn't work.
If you need more information on a script error, then hover over the red
x icon in the Script Editor's margin:
On this page
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 store. This step assumes that the script doesn't include so many errors that it needs to be unpublished (removed) from your 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 to your 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 updates 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 reports the script's resource usage. More complex scripts 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.
Learn more about: