@@ -169,31 +169,47 @@ export class Pixi {
169169 */
170170 @cache ( 1_000 , true , 1_000 )
171171 public async getPixiInfo ( cwd : string ) : Promise < PixiInfo | undefined > {
172- const infoOutput = await exec ( this . command , [ 'info' , '--json' ] , {
173- cwd,
174- throwOnStdErr : false ,
175- } ) . catch ( traceError ) ;
176- if ( ! infoOutput ) {
172+ try {
173+ const infoOutput = await exec ( this . command , [ 'info' , '--json' ] , {
174+ cwd,
175+ throwOnStdErr : false ,
176+ } ) ;
177+
178+ if ( ! infoOutput || ! infoOutput . stdout ) {
179+ return undefined ;
180+ }
181+
182+ const pixiInfo : PixiInfo = JSON . parse ( infoOutput . stdout ) ;
183+ return pixiInfo ;
184+ } catch ( error ) {
185+ traceError ( `Failed to get pixi info for ${ cwd } ` , error ) ;
177186 return undefined ;
178187 }
179-
180- const pixiInfo : PixiInfo = JSON . parse ( infoOutput . stdout ) ;
181- return pixiInfo ;
182188 }
183189
184190 /**
185191 * Runs `pixi --version` and returns the version part of the output.
186192 */
187193 @cache ( 30_000 , true , 10_000 )
188194 public async getVersion ( ) : Promise < string | undefined > {
189- const versionOutput = await exec ( this . command , [ '--version' ] , {
190- throwOnStdErr : false ,
191- } ) . catch ( traceError ) ;
192- if ( ! versionOutput ) {
195+ try {
196+ const versionOutput = await exec ( this . command , [ '--version' ] , {
197+ throwOnStdErr : false ,
198+ } ) ;
199+ if ( ! versionOutput || ! versionOutput . stdout ) {
200+ return undefined ;
201+ }
202+
203+ const versionParts = versionOutput . stdout . split ( ' ' ) ;
204+ if ( versionParts . length < 2 ) {
205+ return undefined ;
206+ }
207+
208+ return versionParts [ 1 ] . trim ( ) ;
209+ } catch ( error ) {
210+ traceError ( `Failed to get pixi version` , error ) ;
193211 return undefined ;
194212 }
195-
196- return versionOutput . stdout . split ( ' ' ) [ 1 ] . trim ( ) ;
197213 }
198214
199215 /**
@@ -279,13 +295,24 @@ export async function getPixiEnvironmentFromInterpreter(
279295
280296 // Usually the pixi environments are stored under `<projectDir>/.pixi/envs/<environment>/`. So,
281297 // we walk backwards to determine the project directory.
282- const envName = path . basename ( prefix ) ;
283- const envsDir = path . dirname ( prefix ) ;
284- const dotPixiDir = path . dirname ( envsDir ) ;
285- const pixiProjectDir = path . dirname ( dotPixiDir ) ;
298+ let envName : string | undefined ;
299+ let envsDir : string ;
300+ let dotPixiDir : string ;
301+ let pixiProjectDir : string ;
302+ let pixiInfo : PixiInfo | undefined ;
303+
304+ try {
305+ envName = path . basename ( prefix ) ;
306+ envsDir = path . dirname ( prefix ) ;
307+ dotPixiDir = path . dirname ( envsDir ) ;
308+ pixiProjectDir = path . dirname ( dotPixiDir ) ;
309+
310+ // Invoke pixi to get information about the pixi project
311+ pixiInfo = await pixi . getPixiInfo ( pixiProjectDir ) ;
312+ } catch ( error ) {
313+ traceWarn ( 'Error processing paths or getting Pixi Info:' , error ) ;
314+ }
286315
287- // Invoke pixi to get information about the pixi project
288- const pixiInfo = await pixi . getPixiInfo ( pixiProjectDir ) ;
289316 if ( ! pixiInfo || ! pixiInfo . project_info ) {
290317 traceWarn ( `failed to determine pixi project information for the interpreter at ${ interpreterPath } ` ) ;
291318 return undefined ;
0 commit comments