({
error,
blockName,
blockId,
executionId,
logContext,
}: NotifyBlockErrorParams)
| 258 | const recentErrorNotifications = new Map<string, number>() |
| 259 | |
| 260 | const notifyBlockError = ({ |
| 261 | error, |
| 262 | blockName, |
| 263 | blockId, |
| 264 | executionId, |
| 265 | logContext, |
| 266 | }: NotifyBlockErrorParams) => { |
| 267 | const settings = getQueryClient().getQueryData<GeneralSettings>(generalSettingsKeys.settings()) |
| 268 | const isErrorNotificationsEnabled = settings?.errorNotificationsEnabled ?? true |
| 269 | |
| 270 | if (!isErrorNotificationsEnabled) return |
| 271 | |
| 272 | try { |
| 273 | const errorMessage = normalizeConsoleError(error) ?? String(error) |
| 274 | const displayName = blockName || 'Unknown Block' |
| 275 | const copilotMessage = `${errorMessage}\n\nError in ${displayName}.\n\nPlease fix this.` |
| 276 | |
| 277 | const now = Date.now() |
| 278 | for (const [key, shownAt] of recentErrorNotifications) { |
| 279 | if (now - shownAt >= NOTIFY_DEDUP_WINDOW_MS) recentErrorNotifications.delete(key) |
| 280 | } |
| 281 | const dedupKey = `${getBlockExecutionKey(blockId, executionId)}: ${errorMessage}` |
| 282 | const lastShownAt = recentErrorNotifications.get(dedupKey) |
| 283 | if (lastShownAt !== undefined && now - lastShownAt < NOTIFY_DEDUP_WINDOW_MS) return |
| 284 | recentErrorNotifications.set(dedupKey, now) |
| 285 | |
| 286 | toast.error(displayName, { |
| 287 | description: errorMessage, |
| 288 | action: { |
| 289 | label: 'Fix in Chat', |
| 290 | onClick: () => sendMothershipMessage(copilotMessage), |
| 291 | }, |
| 292 | }) |
| 293 | } catch (notificationError) { |
| 294 | logger.error('Failed to create block error notification', { |
| 295 | ...logContext, |
| 296 | error: notificationError, |
| 297 | }) |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | export const useTerminalConsoleStore = create<ConsoleStore>()( |
| 302 | devtools((set, get) => ({ |
no test coverage detected