Summary: Starting in version 3.22022 of Power Apps Studio, if one of the arguments to to the [Clear]Collect function is an error, then the [Clear]Collect expression will return an error - meaning that something like an expression like the one below can now be used to catch errors from data sources:
IfError(Collect(myCache, DataSource), Notify("Error loading data!"))
This only applies to apps with the 'Formula-level error management' feature enabled.
More details: following some feedback from the community, we changed how the [Clear]Collect function behaves if one of its arguments is an error. Take the example below (assuming that the schema for DataSource[1-3] are equivalent), in the OnSelect property of a button:
Collect(
myCollection,
LookUp(DataSource1, Condition1),
LookUp(DataSource2, Condition2),
LookUp(DataSource3, Condition3))
If a user clicked the button, and one of the data sources was unavailable (for example, the table had been removed - which would make the LookUp call return an error), the error would be inserted into the collection itself, and as it was "handled", it would not be shown to the user. Another more common scenario, where the app wants to cache a data source into a local collection:
ClearCollect(
myCache,
DataSource1)
To be consistent with the first example, this would also not return an error, and myCache would have an error as its element. This made checking errors in those expressions harder (as seen in this thread) - we would need to check the records inside the collection.
Starting in version 3.22022, those expressions will return errors, and they can be handled directly by using the IfError function:
IfError(
ClearCollect(myCache, DataSource1),
Notify("Error reading data from DataSource1!"))
We can also directly access the errors that were returned, and trace them out to get more information:
IfError(
ClearCollect(myCache, DataSource1),
Trace("Error loading data source", TraceSeverity.Critical, { errors: AllErrors });
Notify("Error reading data from DataSource1!"))
Hopefully this helps understanding this recent change. As usual, we want your feedback (and we're making changes based on it)! Let us know if you have any questions, concerns, suggestions or bug reports on the error handling feature.
This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.