@@ -88,7 +88,7 @@ export async function getCommandLines(prov: SimpleTaskProvider) {
8888 return actualCommandLines ;
8989}
9090export async function runTaskAndGetResult ( task : vscode . Task ) : Promise < number | undefined > {
91- return await new Promise ( ( resolve , reject ) => {
91+ return await new Promise < number | undefined > ( ( resolve , reject ) => {
9292 let started = false ;
9393
9494 const startDisposable = vscode . tasks . onDidStartTask ( ( e ) => {
@@ -114,17 +114,27 @@ export async function runTaskAndGetResult(task: vscode.Task): Promise<number | u
114114 * error occured during startup. Reject the promise.
115115 */
116116 if ( ! started ) {
117- reject (
118- Error (
119- `The task '${ getConventionalTaskLabel (
120- task
121- ) } ' was not started, likely due to an error`
122- )
123- ) ;
117+ const msg = `The task '${ getConventionalTaskLabel (
118+ task
119+ ) } ' was not started, likely due to an error.\n`;
120+ reject ( Error ( msg ) ) ;
124121 }
125122 } , 3000 ) ;
126123
127124 void vscode . tasks . executeTask ( task ) ;
125+ } ) . catch ( async ( reason ) => {
126+ if ( reason instanceof Error ) {
127+ let msg = 'The current list of tasks is:\n' ;
128+ msg += await vscode . tasks . fetchTasks ( { type : task . definition . type } ) . then (
129+ ( list ) => list . map ( getConventionalTaskLabel ) . join ( '\n' ) ,
130+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
131+ ( reason ) => `fetchTasks promise was rejected: ${ reason } `
132+ ) ;
133+
134+ reason . message += '\n' + msg ;
135+ }
136+
137+ return Promise . reject ( reason ) ;
128138 } ) ;
129139}
130140export function getCmdLine ( exec : vscode . ShellExecution ) {
@@ -156,7 +166,14 @@ export async function testTask(
156166 if ( execStatus != 0 ) {
157167 let msg = `Got status ${ execStatus ?? "'undefined'" } for task '${ taskName } '` ;
158168 if ( task . execution instanceof vscode . ShellExecution ) {
159- msg += ` with command line: ${ getCmdLine ( task . execution ) } ` ;
169+ const cmdLine = [ task . execution . command ] . concat ( task . execution . args ) . map ( ( arg ) => {
170+ if ( typeof arg == 'string' ) {
171+ return arg ;
172+ } else {
173+ return arg . value ;
174+ }
175+ } ) ;
176+ msg += ` with command line: ${ cmdLine . join ( ' ' ) } ` ;
160177
161178 try {
162179 /**
@@ -166,19 +183,7 @@ export async function testTask(
166183 msg += `\nTrying to re-run the command explicitly in: ${ cwd } ` ;
167184 const env = { ...process . env } ;
168185 setTerminalEnvironment ( env ) ;
169- const cp = spawnSync (
170- typeof task . execution . command == 'string'
171- ? task . execution . command
172- : task . execution . command . value ,
173- task . execution . args . map ( ( arg ) => {
174- if ( typeof arg == 'string' ) {
175- return arg ;
176- } else {
177- return arg . value ;
178- }
179- } ) ,
180- { cwd : cwd , env : env }
181- ) ;
186+ const cp = spawnSync ( cmdLine [ 0 ] , cmdLine . slice ( 1 ) , { cwd : cwd , env : env } ) ;
182187
183188 // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
184189 msg += `\nProcess ended with exit code ${ cp . status } and output:\n` ;
0 commit comments