88import { TaskRunError , TaskRunErrorCodes } from "@trigger.dev/core/v3/schemas" ;
99import { DevCommandOptions } from "../commands/dev.js" ;
1010import {
11+ aiHelpLink ,
1112 chalkError ,
1213 chalkGrey ,
1314 chalkLink ,
@@ -24,6 +25,7 @@ import {
2425import { eventBus , EventBusEventArgs } from "../utilities/eventBus.js" ;
2526import { logger } from "../utilities/logger.js" ;
2627import { Socket } from "socket.io-client" ;
28+ import { BundleError } from "../build/bundle.js" ;
2729
2830export type DevOutputOptions = {
2931 name : string | undefined ;
@@ -45,6 +47,23 @@ export function startDevOutput(options: DevOutputOptions) {
4547 logger . log ( chalkGrey ( "○ Building background worker…" ) ) ;
4648 } ;
4749
50+ const buildFailed = ( ...[ target , error ] : EventBusEventArgs < "buildFailed" > ) => {
51+ const errorText = error instanceof Error ? error . message : "Unknown error" ;
52+ const stack = error instanceof Error ? error . stack : undefined ;
53+
54+ let issues : string [ ] = [ ] ;
55+
56+ if ( error instanceof BundleError ) {
57+ issues = error . issues ?. map ( ( issue ) => `${ issue . text } (${ issue . location ?. file } )` ) ?? [ ] ;
58+ }
59+
60+ aiHelpLink ( {
61+ dashboardUrl,
62+ project : config . project ,
63+ query : `Build failed:\n ${ errorText } \n${ issues . join ( "\n" ) } \n${ stack } ` ,
64+ } ) ;
65+ } ;
66+
4867 const workerSkipped = ( ) => {
4968 logger . log ( chalkGrey ( "○ No changes detected, skipping build…" ) ) ;
5069 } ;
@@ -83,12 +102,18 @@ export function startDevOutput(options: DevOutputOptions) {
83102 ...[ buildManifest , error ] : EventBusEventArgs < "backgroundWorkerIndexingError" >
84103 ) => {
85104 if ( error instanceof TaskIndexingImportError ) {
105+ let errorText = "" ;
86106 for ( const importError of error . importErrors ) {
87107 prettyError (
88108 `Could not import ${ importError . file } ` ,
89109 importError . stack ?? importError . message
90110 ) ;
111+ errorText += `Could not import ${ importError . file } :\n ${
112+ importError . stack ?? importError . message
113+ } \n`;
91114 }
115+
116+ aiHelpLink ( { dashboardUrl, project : config . project , query : errorText } ) ;
92117 } else if ( error instanceof TaskMetadataParseError ) {
93118 const errorStack = createTaskMetadataFailedErrorStack ( {
94119 version : "v1" ,
@@ -97,11 +122,21 @@ export function startDevOutput(options: DevOutputOptions) {
97122 } ) ;
98123
99124 prettyError ( `Could not parse task metadata` , errorStack ) ;
125+ aiHelpLink ( {
126+ dashboardUrl,
127+ project : config . project ,
128+ query : `Could not parse task metadata:\n ${ errorStack } ` ,
129+ } ) ;
100130 } else {
101131 const errorText = error instanceof Error ? error . message : "Unknown error" ;
102132 const stack = error instanceof Error ? error . stack : undefined ;
103133
104134 prettyError ( `Build failed: ${ errorText } ` , stack ) ;
135+ aiHelpLink ( {
136+ dashboardUrl,
137+ project : config . project ,
138+ query : `Build failed:\n ${ errorText } \n${ stack } ` ,
139+ } ) ;
105140 }
106141 } ;
107142
@@ -184,6 +219,7 @@ export function startDevOutput(options: DevOutputOptions) {
184219
185220 eventBus . on ( "rebuildStarted" , rebuildStarted ) ;
186221 eventBus . on ( "buildStarted" , buildStarted ) ;
222+ eventBus . on ( "buildFailed" , buildFailed ) ;
187223 eventBus . on ( "workerSkipped" , workerSkipped ) ;
188224 eventBus . on ( "backgroundWorkerInitialized" , backgroundWorkerInitialized ) ;
189225 eventBus . on ( "runStarted" , runStarted ) ;
@@ -195,6 +231,7 @@ export function startDevOutput(options: DevOutputOptions) {
195231 return ( ) => {
196232 eventBus . off ( "rebuildStarted" , rebuildStarted ) ;
197233 eventBus . off ( "buildStarted" , buildStarted ) ;
234+ eventBus . off ( "buildFailed" , buildFailed ) ;
198235 eventBus . off ( "workerSkipped" , workerSkipped ) ;
199236 eventBus . off ( "backgroundWorkerInitialized" , backgroundWorkerInitialized ) ;
200237 eventBus . off ( "runStarted" , runStarted ) ;
0 commit comments