Skip to content

Commit 381256c

Browse files
committed
Additional logging
1 parent 851d0a3 commit 381256c

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

src/client/chat/createVirtualEnvTool.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
getDisplayVersion,
2222
getEnvDetailsForResponse,
2323
IResourceReference,
24+
isCancellationError,
2425
raceCancellationError,
2526
} from './utils';
2627
import { resolveFilePath } from './utils';
@@ -35,6 +36,7 @@ import { convertEnvInfoToPythonEnvironment } from '../pythonEnvironments/legacyI
3536
import { sortInterpreters } from '../interpreter/helpers';
3637
import { isStableVersion } from '../pythonEnvironments/info/pythonVersion';
3738
import { createVirtualEnvironment } from '../pythonEnvironments/creation/createEnvApi';
39+
import { traceError, traceWarn } from '../logging';
3840

3941
export class CreateVirtualEnvTool implements LanguageModelTool<IResourceReference> {
4042
private readonly terminalExecutionService: TerminalCodeExecutionProvider;
@@ -64,6 +66,7 @@ export class CreateVirtualEnvTool implements LanguageModelTool<IResourceReferenc
6466
const resource = resolveFilePath(options.input.resourcePath);
6567
let info = await this.getPreferredEnvForCreation(resource);
6668
if (!info) {
69+
traceWarn(`${CreateVirtualEnvTool.toolName} tool not invoked, no preferred environment found.`);
6770
return;
6871
}
6972
const { workspaceFolder, preferredGlobalPythonEnv } = info;
@@ -82,13 +85,15 @@ export class CreateVirtualEnvTool implements LanguageModelTool<IResourceReferenc
8285
token,
8386
);
8487
if (!created?.path) {
88+
traceWarn(`${CreateVirtualEnvTool.toolName} tool not invoked, no preferred environment found.`);
8589
return;
8690
}
8791
// Wait a few secs to ensure the env is selected as the active environment..
8892
// If this doesn't work, then something went wrong.
8993
await raceTimeout(5_000, interpreterChanged);
9094
const env = await this.api.resolveEnvironment(created.path);
9195
if (!env) {
96+
traceError(`${CreateVirtualEnvTool.toolName} tool not invoked, no preferred environment found.`);
9297
return;
9398
}
9499
return await getEnvDetailsForResponse(
@@ -99,6 +104,16 @@ export class CreateVirtualEnvTool implements LanguageModelTool<IResourceReferenc
99104
resource,
100105
token,
101106
);
107+
} catch (ex) {
108+
if (!isCancellationError(ex)) {
109+
traceError(
110+
`${
111+
CreateVirtualEnvTool.toolName
112+
} tool failed to create virtual environment for resource ${resource?.toString()}`,
113+
ex,
114+
);
115+
}
116+
throw ex;
102117
} finally {
103118
disposables.dispose();
104119
}

src/client/chat/installPackagesTool.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT License.
33

44
import {
5-
CancellationError,
65
CancellationToken,
76
l10n,
87
LanguageModelTextPart,
@@ -18,6 +17,7 @@ import {
1817
getEnvDisplayName,
1918
getToolResponseIfNotebook,
2019
IResourceReference,
20+
isCancellationError,
2121
isCondaEnv,
2222
raceCancellationError,
2323
} from './utils';
@@ -74,7 +74,7 @@ export class InstallPackagesTool implements LanguageModelTool<IInstallPackageArg
7474
const resultMessage = `Successfully installed ${packagePlurality}: ${options.input.packageList.join(', ')}`;
7575
return new LanguageModelToolResult([new LanguageModelTextPart(resultMessage)]);
7676
} catch (error) {
77-
if (error instanceof CancellationError) {
77+
if (isCancellationError(error)) {
7878
throw error;
7979
}
8080
const errorMessage = `An error occurred while installing ${packagePlurality}: ${error}`;

src/client/chat/selectEnvTool.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { SelectEnvironmentResult } from '../interpreter/configuration/interprete
3636
import { Common, InterpreterQuickPickList } from '../common/utils/localize';
3737
import { showQuickPick } from '../common/vscodeApis/windowApis';
3838
import { DisposableStore } from '../common/utils/resourceLifecycle';
39+
import { traceError, traceVerbose, traceWarn } from '../logging';
3940

4041
interface ISelectPythonEnvToolArguments extends IResourceReference {
4142
reason?: 'cancelled';
@@ -71,14 +72,29 @@ export class SelectPythonEnvTool implements LanguageModelTool<ISelectPythonEnvTo
7172
}),
7273
)) as SelectEnvironmentResult | undefined;
7374
if (result?.path) {
75+
traceVerbose(`User selected a Python environment ${result.path} in Select Python Tool.`);
7476
selected = true;
77+
} else {
78+
traceWarn(`User did not select a Python environment in Select Python Tool.`);
7579
}
7680
} else {
7781
selected = await showCreateAndSelectEnvironmentQuickPick(resource, this.serviceContainer);
82+
if (selected) {
83+
traceVerbose(`User selected a Python environment ${selected} in Select Python Tool(2).`);
84+
} else {
85+
traceWarn(`User did not select a Python environment in Select Python Tool(2).`);
86+
}
7887
}
7988
const env = selected
8089
? await this.api.resolveEnvironment(this.api.getActiveEnvironmentPath(resource))
8190
: undefined;
91+
if (selected && !env) {
92+
traceError(
93+
`User selected a Python environment, but it could not be resolved. This is unexpected. Environment: ${this.api.getActiveEnvironmentPath(
94+
resource,
95+
)}`,
96+
);
97+
}
8298
if (selected && env) {
8399
return await getEnvDetailsForResponse(
84100
env,

0 commit comments

Comments
 (0)