@@ -3,6 +3,39 @@ import { mkdir } from 'node:fs/promises'
33import { platform } from 'node:os'
44import { resolve } from 'node:path'
55
6+ /**
7+ * Normalizes tar error messages across different platforms
8+ */
9+ function normalizeTarError ( stderr : string ) : string {
10+ const errorMessage = stderr . trim ( )
11+
12+ // File not found errors
13+ if (
14+ errorMessage . includes ( 'Cannot open' ) ||
15+ errorMessage . includes ( 'Failed to open' ) ||
16+ errorMessage . includes ( 'No such file or directory' )
17+ ) {
18+ return 'tar command failed: File not found'
19+ }
20+
21+ // Invalid archive format errors
22+ if (
23+ errorMessage . includes ( 'Unrecognized archive format' ) ||
24+ errorMessage . includes ( 'Error opening archive' ) ||
25+ errorMessage . includes ( 'incorrect header check' )
26+ ) {
27+ return 'tar command failed: Invalid archive format'
28+ }
29+
30+ // General extraction errors
31+ if ( errorMessage . includes ( 'Error is not recoverable' ) || errorMessage . includes ( 'Child returned status' ) ) {
32+ return 'tar command failed: Extraction error'
33+ }
34+
35+ // If no specific pattern matches, return a generic message
36+ return `tar command failed: ${ errorMessage } `
37+ }
38+
639export async function extractTarGz ( archivePath : string , outputDir : string ) : Promise < void > {
740 await mkdir ( outputDir , { recursive : true } )
841
@@ -21,8 +54,8 @@ export async function extractTarGz(archivePath: string, outputDir: string): Prom
2154 if ( code === 0 ) {
2255 resolve ( )
2356 } else {
24- // Include stderr in error message for better debugging
25- const errorMsg = stderr . trim ( ) || `${ tarCmd } command failed with code ${ code } `
57+ // Normalize error message for consistent cross-platform behavior
58+ const errorMsg = stderr . trim ( ) ? normalizeTarError ( stderr ) : `${ tarCmd } command failed with code ${ code } `
2659 reject ( new Error ( errorMsg ) )
2760 }
2861 } )
0 commit comments