Throw a user-facing error

When running functions in other parts of the platform, such as Workshop or Actions, you may want to throw an error with a detailed message. To do so, throw a UserFacingError from the functions.api module. For example:

Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 from functions.api import function, UserFacingError from ontology_sdk import FoundryClient from ontology_sdk.ontology.object_sets import AircraftObjectSet from ontology_sdk.ontology.objects import Aircraft @function(edits=[Aircraft]) def edit_exactly_five_aircraft( aircraft_object_set: AircraftObjectSet ) -> list[OntologyEdit]: aircraft = list(aircraft_object_set) if not len(aircraft) == 5: raise UserFacingError(f"Pass in exactly 5 aircraft. Received ${len(aircraft)}.") ... # edit the objects

When running this as a Function-backed Action in a Workshop application with an incorrect number of employees, users will see the following error:

user-facing-error

By adding a detailed user facing error message, you can help other users of your Function quickly identify and fix the issue.