Handling and preventing action errors
When building actions, you may encounter unexpected errors. These usually occur because an action is executed under conditions the builder did not anticipate. This page explains the most common causes, how to prevent them, and what to do when they occur.
This guide explains how to:
-
Prevent common action-building errors.
-
Handle unexpected runtime errors in your application.
-
Troubleshoot and solve errors effectively.
Common action-building errors
Builders most often run into the following issues:
-
Empty objects or collections
Attempting to perform an action on an empty object or collection will cause an error. The solution for this is to use 'condition steps' to check whether an object exists or a collection isn't empty. -
Unavailable properties
Using a property that has not yet been compiled in the application results in an error message stating the property cannot be found. -
Happy flow only
Actions are sometimes designed only for the "happy flow" without error handling, which causes failures when conditions are not ideal. (A "happy flow" is the ideal execution path in a program where everything works as intended without errors or exceptions.) -
Removed properties
If a property is deleted from the data model but is still referenced in an action (or a sub-action), the action will fail. -
Compile errors from others
Sometimes errors are introduced by changes from other builders. If this happens, you will see compile errors in your logs. If you encounter these compile errors, check in with colleagues if they've recently made any changes.
Best Practices to Prevent Errors
To reduce the likelihood of action errors, follow these standards:
-
Use condition steps
Use condition steps to check whether an object or collection exists and data is present before trying to execute the next step. -
Add error handling
Implement error handling in every action, even if you expect it to succeed. -
Manage dependencies carefully
Never delete a model, property, or relation without first checking its dependencies across actions and pages. -
Use logging responsibly
-
Enable debug logging only when investigating an issue.
-
Disable debug logging afterward to avoid performance impact.
-
Remove temporary log messages after resolving an error.
-
-
Secure data
Use authentication where applicable to prevent possible data leaks.
Troubleshooting Steps
When an error occurs:
-
Check inputs
Verify that the expected inputs are sent from the form, button, or page (use tools like the GraphQL Network Inspector). -
Review logs
Open the application logs to see what went wrong. -
Enable debug logging
Turn on debug logging to capture detailed information and check incoming values. -
Use log messages
Place log messages after each event to track where the error occurs. -
Collaborate
If the error persists:-
Ask a colleague to review the issue.
-
Check the Betty Blocks Community for known errors and solutions.
-
Recommended Debugging Patterns
-
Add log steps between each action function to trace execution.
-
Share your findings with your team; many errors are already known, and solutions may be available.