applyPlugins method
Implementation
Future<RawEvent?> applyPlugins(PluginType type, RawEvent event) async {
RawEvent? result = event;
final plugins = _plugins[type];
if (plugins != null) {
for (var plugin in plugins) {
if (result != null) {
try {
final pluginResult = plugin.execute(result);
// Each destination is independent from each other, so we don't
// roll over changes caused internally in each one of their
// processing. We still await the future so that track() does not
// resolve before the destination has queued the event — without
// this, a flush() called immediately after track() may miss the
// event because it has not yet reached the QueueFlushingPlugin.
if (type != PluginType.destination) {
result = await pluginResult;
} else {
await pluginResult;
}
} catch (error) {
final pluginName = plugin is DestinationPlugin
? "Destination ${plugin.key}"
: "Plugin ${plugin.runtimeType}";
reportInternalError(
PluginError("$pluginName failed to execute", error),
analytics: plugin.analytics);
if (plugin.type == PluginType.destination) {
log("$pluginName failed to execute: $error",
kind: LogFilterKind.warning);
}
}
}
}
}
return result;
}