Error handling when working with collection attributes
This functionality is available for Creatio 8.3.4 and later.
Creatio provides a dedicated public API in the @creatio/interface-designer library that lets you bind a Freedom UI component property to a collection of view model attributes directly from the setup area code. Learn more: Working with collection attributes when implementing Freedom UI Designer setup area.
The API provides a public SchemaValidationError hierarchy for predictable error handling. All public schema-editing errors inherit from SchemaValidationError. SchemaValidationError is the base class for all public schema-editing errors. This means you can use it as a catch-all fallback to handle any schema validation failure in a single catch block.
Recommendations for error handling
The following recommendations help you handle errors predictably and maintain consistent setup area state:
-
Check capability before removal. Call the
canRemoveAttribute()orcanRemoveDataSource()method before removing to avoid errors when the attribute or data source is still referenced elsewhere.Example that checks capability before removal/* Check whether the collection attribute can be safely removed. */const canRemove = await collectionAttributeEditor.canRemoveAttribute('Code');if (canRemove) {await collectionAttributeEditor.removeAttribute('Code');}/* Check whether the data source can be safely removed. */const canRemoveDS = await schemaEditor.modelEditor.canRemoveDataSource('CityDS');if (canRemoveDS) {await schemaEditor.modelEditor.removeDataSource('CityDS');} -
Catch specific validation errors. Use
instanceofchecks against specific error classes such asDataSourceAlreadyExistsErrororUnsupportedDataSourceTypeErrorto handle each case explicitly.Example that catches specific validation errorsimport {DataSourceAlreadyExistsError,SchemaValidationError,UnsupportedDataSourceTypeError,} from '@creatio/interface-designer';try {await schemaEditor.modelEditor.createDataSource('CityDS', {type: DataSourceType.EntityDataSource,entitySchemaName: 'City',});} catch (error) {if (error instanceof DataSourceAlreadyExistsError) {console.error(`Data source '${error.dataSourceName}' already exists.`);return;}if (error instanceof UnsupportedDataSourceTypeError) {console.error(`Data source type '${error.dataSourceType}' is not supported.`);return;}if (error instanceof SchemaValidationError) {console.error(`Schema validation failed: ${error.message}`);return;}throw error;} -
Keep user-friendly messages in the setup area. Catch low-level schema API errors, map them to human-readable messages, and maintain consistent setup area state.
The following example keeps user-friendly messages in the setup area.
Example that keeps user-friendly messages in the setup areatry {await this._bindItemsToDataSource(dataSourceName);/* Display a success message to the user. */this._setOperationMessage('success',`Collection attribute was bound to data source '${dataSourceName}'.`);} catch (error) {/* Display a user-friendly error message. */const message = error instanceof Error ? error.message : 'Unknown error';this._setOperationMessage('error', `Error binding to data source: ${message}`);} -
Use
instanceof SchemaValidationErroras a fallback.SchemaValidationErroroverridesSymbol.hasInstance, soinstanceofchecks work reliably across bundle boundaries, including remote modules and Module Federation scenarios where the same library may be loaded from different bundles.try {await schemaEditor.viewModelEditor.createAttribute('Items', {isCollection: true,bindToModel: { dataSourceName: 'CityDS' },});} catch (error) {if (error instanceof SchemaValidationError) {console.error('Schema validation error:', error.message);}}
Common errors
The following table lists common errors and their solutions when working with collection attributes.
Error | Solution |
|---|---|
Attribute with the target name already exists but is not a collection. |
|
Nested attribute already exists but has the wrong binding. |
|
Collection attribute is removed but the data source is still used elsewhere. |
|
Data source already exists but points to another object schema. |
|
const editor = await schemaEditor.modelEditor.getDataSourceEditor(dataSourceName);
if (editor?.dataSourceType === DataSourceType.EntityDataSource
&& editor.entitySchemaName !== expectedEntityName) {
/* Data source 'CityDS' is already bound to 'Account', not 'City'. */
}
Error handling when working with data sources
The following error classes may be thrown when creating, reading, or removing data sources and their attributes.
Error class | Trigger | Solution |
|---|---|---|
DataSourceAlreadyExistsError | Creating a data source with an existing name. | Reuse it if compatible or show a conflict message. |
DataSourceNotFoundError | Calling the | Validate the data source name before operating on it. |
DataSourceAttributeAlreadyExistsError | Creating an existing data source attribute. | Reuse the existing attribute or verify its configuration before proceeding. |
BoundDataSourceRemovalError | Removing a data source that is still used elsewhere. | Call the |
UnsupportedDataSourceTypeError | The data source type is not supported by the current public API. | Validate |
Error handling when working with view model attributes
The following error classes may be thrown when creating, reading, or removing view model attributes.
Error class | Trigger | Solution |
|---|---|---|
ViewModelAttributeAlreadyExistsError | Creating an attribute with an existing name. | Reuse the existing attribute or remove and recreate it if safe. |
ViewModelAttributeNotFoundError | Removing or resolving an invalid attribute path. | Verify attribute name or path before removal. |
ViewModelAttributeNotBoundError | Calling the | Check attribute type and binding state before reading binding. |
BoundViewModelAttributeRemovalError | Removing an attribute that is still referenced. | Call the |
UnsupportedViewModelAttributeDataError | Passing unsupported | Verify that the options correspond to constant, scalar binding, or collection binding. |
Error handling when working with view node properties
The following error classes may be thrown when reading or writing view node properties.
Error class | Trigger | Solution |
|---|---|---|
UnsupportedViewNodePropertyTypeError | A view-node property contains an unsupported binding type. | Check the returned property type before processing it. |
See also
Working with collection attributes when implementing Freedom UI Designer setup area
Freedom UI Designer setup area for a custom Freedom UI component
Implement a Freedom UI Designer setup area for a custom Freedom UI component