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