Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Troubleshooting your Shopify function in production

Solved

Troubleshooting your Shopify function in production

Sam9516
Shopify Partner
44 1 15

Here are the steps to troubleshoot your Shopify function in production,

 

1) Create a mechanism in your function to throw exception/cause panic based on a certain trigger, for example, if the first name is entered as "Debug". This will ensure that this panic is not created in the function randomly when customers enter their details during checkout (Nobody has the first name of debug, right?).

 

Screenshot 2023-10-25 at 11.17.31 PM.png

This is how to do it in Rust (Place it near the end of the function, preferably),

 

if first_name == "Debug" {
    panic!("Debug mode activated");
}

 

 

2) Create a mechanism for merchants to follow and generate and share the error logs with you. For example, you can show them a modal with steps to follow, the steps can look something like this,

  - Use the first name of Debug at the checkout to generate the error.

  - Go to the customization in the settings and click on share the error report with the developer.

 

3) Once the merchant follows your instructions and successfully generates the error and shares with you, you will have all the details of what is going on at their checkout and what output did your function generate in response to the input it received.

 

Hope this helps.

Accepted Solutions (2)

Nick_Wesselman
Shopify Staff
171 43 73

This is an accepted solution.

Thanks for this @Sam9516!

For JavaScript/TypeScript developers, you can do the same thing with something like

 

if (firstName == "Debug") {
  throw "Debug mode activated";
}

 



Nick Wesselman | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

View solution in original post

Nick_Wesselman
Shopify Staff
171 43 73

This is an accepted solution.

This sort of workflow shouldn't be needed anymore! It’s now possible for merchants to share 24hr of execution logs for all functions in your app from the Apps section of admin. This should remove the need for “debug” modes and other hacks to force your function to crash, just to see the input and output.

 

https://shopify.dev/docs/apps/build/functions/monitoring-and-errors#share-app-function-logs

Nick Wesselman | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

View solution in original post

Replies 2 (2)

Nick_Wesselman
Shopify Staff
171 43 73

This is an accepted solution.

Thanks for this @Sam9516!

For JavaScript/TypeScript developers, you can do the same thing with something like

 

if (firstName == "Debug") {
  throw "Debug mode activated";
}

 



Nick Wesselman | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

Nick_Wesselman
Shopify Staff
171 43 73

This is an accepted solution.

This sort of workflow shouldn't be needed anymore! It’s now possible for merchants to share 24hr of execution logs for all functions in your app from the Apps section of admin. This should remove the need for “debug” modes and other hacks to force your function to crash, just to see the input and output.

 

https://shopify.dev/docs/apps/build/functions/monitoring-and-errors#share-app-function-logs

Nick Wesselman | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog