@@ -62,6 +62,45 @@ const shouldSkipEntry = (output: any): boolean => {
6262 return false
6363}
6464
65+ interface NotifyBlockErrorParams {
66+ error : unknown
67+ blockName : string
68+ workflowId ?: string
69+ logContext : Record < string , unknown >
70+ }
71+
72+ /**
73+ * Sends an error notification for a block failure if error notifications are enabled.
74+ */
75+ const notifyBlockError = ( { error, blockName, workflowId, logContext } : NotifyBlockErrorParams ) => {
76+ const settings = getQueryClient ( ) . getQueryData < GeneralSettings > ( generalSettingsKeys . settings ( ) )
77+ const isErrorNotificationsEnabled = settings ?. errorNotificationsEnabled ?? true
78+
79+ if ( ! isErrorNotificationsEnabled ) return
80+
81+ try {
82+ const errorMessage = String ( error )
83+ const displayName = blockName || 'Unknown Block'
84+ const displayMessage = `${ displayName } : ${ errorMessage } `
85+ const copilotMessage = `${ errorMessage } \n\nError in ${ displayName } .\n\nPlease fix this.`
86+
87+ useNotificationStore . getState ( ) . addNotification ( {
88+ level : 'error' ,
89+ message : displayMessage ,
90+ workflowId,
91+ action : {
92+ type : 'copilot' ,
93+ message : copilotMessage ,
94+ } ,
95+ } )
96+ } catch ( notificationError ) {
97+ logger . error ( 'Failed to create block error notification' , {
98+ ...logContext ,
99+ error : notificationError ,
100+ } )
101+ }
102+ }
103+
65104export const useTerminalConsoleStore = create < ConsoleStore > ( ) (
66105 devtools (
67106 persist (
@@ -154,35 +193,12 @@ export const useTerminalConsoleStore = create<ConsoleStore>()(
154193 const newEntry = get ( ) . entries [ 0 ]
155194
156195 if ( newEntry ?. error ) {
157- const settings = getQueryClient ( ) . getQueryData < GeneralSettings > (
158- generalSettingsKeys . settings ( )
159- )
160- const isErrorNotificationsEnabled = settings ?. errorNotificationsEnabled ?? true
161-
162- if ( isErrorNotificationsEnabled ) {
163- try {
164- const errorMessage = String ( newEntry . error )
165- const blockName = newEntry . blockName || 'Unknown Block'
166- const displayMessage = `${ blockName } : ${ errorMessage } `
167-
168- const copilotMessage = `${ errorMessage } \n\nError in ${ blockName } .\n\nPlease fix this.`
169-
170- useNotificationStore . getState ( ) . addNotification ( {
171- level : 'error' ,
172- message : displayMessage ,
173- workflowId : entry . workflowId ,
174- action : {
175- type : 'copilot' ,
176- message : copilotMessage ,
177- } ,
178- } )
179- } catch ( notificationError ) {
180- logger . error ( 'Failed to create block error notification' , {
181- entryId : newEntry . id ,
182- error : notificationError ,
183- } )
184- }
185- }
196+ notifyBlockError ( {
197+ error : newEntry . error ,
198+ blockName : newEntry . blockName || 'Unknown Block' ,
199+ workflowId : entry . workflowId ,
200+ logContext : { entryId : newEntry . id } ,
201+ } )
186202 }
187203
188204 return newEntry
@@ -376,6 +392,18 @@ export const useTerminalConsoleStore = create<ConsoleStore>()(
376392
377393 return { entries : updatedEntries }
378394 } )
395+
396+ if ( typeof update === 'object' && update . error ) {
397+ const matchingEntry = get ( ) . entries . find (
398+ ( e ) => e . blockId === blockId && e . executionId === executionId
399+ )
400+ notifyBlockError ( {
401+ error : update . error ,
402+ blockName : matchingEntry ?. blockName || 'Unknown Block' ,
403+ workflowId : matchingEntry ?. workflowId ,
404+ logContext : { blockId } ,
405+ } )
406+ }
379407 } ,
380408
381409 cancelRunningEntries : ( workflowId : string ) => {
0 commit comments