@@ -21,6 +21,7 @@ import {
2121 getDisplayVersion ,
2222 getEnvDetailsForResponse ,
2323 IResourceReference ,
24+ isCancellationError ,
2425 raceCancellationError ,
2526} from './utils' ;
2627import { resolveFilePath } from './utils' ;
@@ -35,6 +36,7 @@ import { convertEnvInfoToPythonEnvironment } from '../pythonEnvironments/legacyI
3536import { sortInterpreters } from '../interpreter/helpers' ;
3637import { isStableVersion } from '../pythonEnvironments/info/pythonVersion' ;
3738import { createVirtualEnvironment } from '../pythonEnvironments/creation/createEnvApi' ;
39+ import { traceError , traceWarn } from '../logging' ;
3840
3941export 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 }
0 commit comments