Displaying error messages is a simple way to let the user know that their input or action is not acceptable at the program’s current state. It can also help to catch all errors that may result from a block of code (in a try
) with a single error message to the user.
Using Python Exceptions
Simply raising a Python Exception
(or your own Exception
child class) will create a notification for users when they encounter an issue. The following code will create the error notification shown below:
raise Exception("Put a user friendly error message here. Typically suggest an action or explain what the user may have done wrong")
Additionally, if you can raise a notification as part of a Python try
block, as shown here.
try:
# write your normal code here
except XYZException as e:
raise Exception("Put a user friendly error message here. Typically suggest an action or explain what the user may have done wrong")
Creating a Toast Notification
If you want a more targeted message to appear for users, leverage the PredictException
class from the Virtualitics SDK.
from virtualitics_sdk import PredictException, ...
class StepOne(Step):
def run(self, flow_metadata):
if 2 + 2 != 5:
raise PredictException('There was an error: 2 + 2 is not 5!')
What to Expect
Expect the error to show up transiently as a message in the bottom right or persist (until cleared by the user) in the drawer at the top right and seen by clicking on the notification bell icon.