Skip to content

Commit 38fbf5c

Browse files
authored
Enhance logging in task execution functions for better debugging (#730)
1 parent 66ff5dd commit 38fbf5c

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/features/execution/runAsTask.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
WorkspaceFolder,
1010
} from 'vscode';
1111
import { PythonEnvironment, PythonTaskExecutionOptions } from '../../api';
12+
import { traceInfo } from '../../common/logging';
1213
import { executeTask } from '../../common/tasks.apis';
1314
import { getWorkspaceFolder } from '../../common/workspace.apis';
1415
import { quoteArg } from './execUtils';
@@ -29,6 +30,7 @@ export async function runAsTask(
2930
executable = quoteArg(executable);
3031
const args = environment.execInfo?.activatedRun?.args ?? environment.execInfo?.run.args ?? [];
3132
const allArgs = [...args, ...options.args];
33+
traceInfo(`Running as task: ${executable} ${allArgs.join(' ')}`);
3234

3335
const task = new Task(
3436
{ type: 'python' },

src/features/execution/runInBackground.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as cp from 'child_process';
2-
import { PythonEnvironment, PythonBackgroundRunOptions, PythonProcess } from '../../api';
2+
import { PythonBackgroundRunOptions, PythonEnvironment, PythonProcess } from '../../api';
3+
import { traceError, traceInfo } from '../../common/logging';
34

45
export async function runInBackground(
56
environment: PythonEnvironment,
@@ -9,6 +10,7 @@ export async function runInBackground(
910
environment.execInfo?.activatedRun?.executable ?? environment.execInfo?.run.executable ?? 'python';
1011
const args = environment.execInfo?.activatedRun?.args ?? environment.execInfo?.run.args ?? [];
1112
const allArgs = [...args, ...options.args];
13+
traceInfo(`Running in background: ${executable} ${allArgs.join(' ')}`);
1214

1315
const proc = cp.spawn(executable, allArgs, { stdio: 'pipe', cwd: options.cwd, env: options.env });
1416

@@ -22,8 +24,17 @@ export async function runInBackground(
2224
proc.kill();
2325
}
2426
},
25-
onExit: (listener: (code: number | null, signal: NodeJS.Signals | null) => void) => {
26-
proc.on('exit', listener);
27+
onExit: (listener: (code: number | null, signal: NodeJS.Signals | null, error?: Error | null) => void) => {
28+
proc.on('exit', (code, signal) => {
29+
if (code && code !== 0) {
30+
traceError(`Process exited with error code: ${code}, signal: ${signal}`);
31+
}
32+
listener(code, signal, null);
33+
});
34+
proc.on('error', (error) => {
35+
traceError(`Process error: ${error?.message || error}${error?.stack ? '\n' + error.stack : ''}`);
36+
listener(null, null, error);
37+
});
2738
},
2839
};
2940
}

0 commit comments

Comments
 (0)