@@ -363,17 +363,72 @@ export class CommonRpcManager implements CommonRPCAPI {
363363 commands . executeCommand ( "vscode.openFolder" , uri , true ) ;
364364 return true ;
365365 }
366- zipReadStream . pipe ( unzipper . Parse ( ) ) . on ( "entry" , function ( entry ) {
366+
367+ let extractionError : Error | null = null ;
368+ const parseStream = unzipper . Parse ( ) ;
369+
370+ // Handle errors on the read stream
371+ zipReadStream . on ( "error" , ( error ) => {
372+ extractionError = error ;
373+ window . showErrorMessage ( `Failed to read zip file: ${ error . message } ` ) ;
374+ } ) ;
375+
376+ // Handle errors on the parse stream
377+ parseStream . on ( "error" , ( error ) => {
378+ extractionError = error ;
379+ window . showErrorMessage ( `Failed to parse zip file. The file may be corrupted: ${ error . message } ` ) ;
380+ } ) ;
381+
382+ parseStream . on ( "entry" , function ( entry ) {
383+ // Skip processing if we've already encountered an error
384+ if ( extractionError ) {
385+ entry . autodrain ( ) ;
386+ return ;
387+ }
388+
367389 var isDir = entry . type === "Directory" ;
368390 var fullpath = path . join ( selectedPath , entry . path ) ;
369391 var directory = isDir ? fullpath : path . dirname ( fullpath ) ;
370- if ( ! fs . existsSync ( directory ) ) {
371- fs . mkdirSync ( directory , { recursive : true } ) ;
392+
393+ try {
394+ if ( ! fs . existsSync ( directory ) ) {
395+ fs . mkdirSync ( directory , { recursive : true } ) ;
396+ }
397+ } catch ( error ) {
398+ extractionError = error as Error ;
399+ window . showErrorMessage ( `Failed to create directory "${ directory } ": ${ error instanceof Error ? error . message : String ( error ) } ` ) ;
400+ entry . autodrain ( ) ;
401+ return ;
372402 }
403+
373404 if ( ! isDir ) {
374- entry . pipe ( fs . createWriteStream ( fullpath ) ) ;
405+ const writeStream = fs . createWriteStream ( fullpath ) ;
406+
407+ // Handle write stream errors
408+ writeStream . on ( "error" , ( error ) => {
409+ extractionError = error ;
410+ window . showErrorMessage ( `Failed to write file "${ fullpath } ": ${ error . message } . This may be due to insufficient disk space or permission issues.` ) ;
411+ entry . autodrain ( ) ;
412+ } ) ;
413+
414+ // Handle entry stream errors
415+ entry . on ( "error" , ( error ) => {
416+ extractionError = error ;
417+ window . showErrorMessage ( `Failed to extract entry "${ entry . path } ": ${ error . message } ` ) ;
418+ writeStream . destroy ( ) ;
419+ } ) ;
420+
421+ entry . pipe ( writeStream ) ;
375422 }
376- } ) . on ( "close" , ( ) => {
423+ } ) ;
424+
425+ parseStream . on ( "close" , ( ) => {
426+ if ( extractionError ) {
427+ console . error ( "Extraction failed:" , extractionError ) ;
428+ window . showErrorMessage ( `Sample extraction failed: ${ extractionError . message } ` ) ;
429+ return ;
430+ }
431+
377432 console . log ( "Extraction complete!" ) ;
378433 window . showInformationMessage ( 'Where would you like to open the project?' ,
379434 { modal : true } ,
@@ -393,6 +448,8 @@ export class CommonRpcManager implements CommonRPCAPI {
393448 }
394449 } ) ;
395450 } ) ;
451+
452+ zipReadStream . pipe ( parseStream ) ;
396453 window . showInformationMessage (
397454 successMsg ,
398455 ) ;
0 commit comments