@@ -88,7 +88,7 @@ export async function getCommandLines(prov: SimpleTaskProvider) {
88
88
return actualCommandLines ;
89
89
}
90
90
export 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 ) => {
92
92
let started = false ;
93
93
94
94
const startDisposable = vscode . tasks . onDidStartTask ( ( e ) => {
@@ -114,17 +114,27 @@ export async function runTaskAndGetResult(task: vscode.Task): Promise<number | u
114
114
* error occured during startup. Reject the promise.
115
115
*/
116
116
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 ) ) ;
124
121
}
125
122
} , 3000 ) ;
126
123
127
124
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 ) ;
128
138
} ) ;
129
139
}
130
140
export function getCmdLine ( exec : vscode . ShellExecution ) {
@@ -156,7 +166,14 @@ export async function testTask(
156
166
if ( execStatus != 0 ) {
157
167
let msg = `Got status ${ execStatus ?? "'undefined'" } for task '${ taskName } '` ;
158
168
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 ( ' ' ) } ` ;
160
177
161
178
try {
162
179
/**
@@ -166,19 +183,7 @@ export async function testTask(
166
183
msg += `\nTrying to re-run the command explicitly in: ${ cwd } ` ;
167
184
const env = { ...process . env } ;
168
185
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 } ) ;
182
187
183
188
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
184
189
msg += `\nProcess ended with exit code ${ cp . status } and output:\n` ;
0 commit comments