this repo has no description

claude normalizes tar error messages

+39 -9
+35 -2
src/extract.ts
··· 3 3 import { platform } from 'node:os' 4 4 import { resolve } from 'node:path' 5 5 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 + 6 39 export async function extractTarGz(archivePath: string, outputDir: string): Promise<void> { 7 40 await mkdir(outputDir, { recursive: true }) 8 41 ··· 21 54 if (code === 0) { 22 55 resolve() 23 56 } 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}` 26 59 reject(new Error(errorMsg)) 27 60 } 28 61 })
+1 -4
test/extract.test.ts
··· 19 19 await extractArchive(archivePath, testDir) 20 20 } catch (error) { 21 21 // Expected to fail with gzip/tar error from our native implementation 22 - assert.match( 23 - (error as Error).message, 24 - /tar command failed|Failed to extract|incorrect header check|Error opening archive/, 25 - ) 22 + assert.match((error as Error).message, /tar command failed: Invalid archive format/) 26 23 } 27 24 28 25 // Clean up
+3 -3
test/tar-extraction.test.ts
··· 43 43 try { 44 44 await assert.rejects( 45 45 async () => await extractTarGz(archivePath, testDir), 46 - /No files extracted from archive|tar command failed|Error opening archive/, 46 + /tar command failed: Invalid archive format/, 47 47 ) 48 48 } finally { 49 49 await rm(testDir, { recursive: true }).catch(() => {}) ··· 67 67 try { 68 68 await assert.rejects( 69 69 async () => await extractTarGz(archivePath, testDir), 70 - /No files extracted from archive|tar command failed|Error opening archive/, 70 + /tar command failed: Invalid archive format/, 71 71 ) 72 72 } finally { 73 73 await rm(testDir, { recursive: true }).catch(() => {}) ··· 80 80 81 81 await assert.rejects( 82 82 async () => await extractTarGz(nonExistentPath, outputDir), 83 - /tar command failed|Failed to open/, 83 + /tar command failed: File not found/, 84 84 ) 85 85 }) 86 86