tangled
alpha
login
or
join now
tbeseda.com
/
release-installer
0
fork
atom
this repo has no description
0
fork
atom
overview
issues
pulls
pipelines
claude normalizes tar error messages
tbeseda.com
8 months ago
d4fc0c3b
7f001f46
+39
-9
3 changed files
expand all
collapse all
unified
split
src
extract.ts
test
extract.test.ts
tar-extraction.test.ts
+35
-2
src/extract.ts
···
3
3
import { platform } from 'node:os'
4
4
import { resolve } from 'node:path'
5
5
6
6
+
/**
7
7
+
* Normalizes tar error messages across different platforms
8
8
+
*/
9
9
+
function normalizeTarError(stderr: string): string {
10
10
+
const errorMessage = stderr.trim()
11
11
+
12
12
+
// File not found errors
13
13
+
if (
14
14
+
errorMessage.includes('Cannot open') ||
15
15
+
errorMessage.includes('Failed to open') ||
16
16
+
errorMessage.includes('No such file or directory')
17
17
+
) {
18
18
+
return 'tar command failed: File not found'
19
19
+
}
20
20
+
21
21
+
// Invalid archive format errors
22
22
+
if (
23
23
+
errorMessage.includes('Unrecognized archive format') ||
24
24
+
errorMessage.includes('Error opening archive') ||
25
25
+
errorMessage.includes('incorrect header check')
26
26
+
) {
27
27
+
return 'tar command failed: Invalid archive format'
28
28
+
}
29
29
+
30
30
+
// General extraction errors
31
31
+
if (errorMessage.includes('Error is not recoverable') || errorMessage.includes('Child returned status')) {
32
32
+
return 'tar command failed: Extraction error'
33
33
+
}
34
34
+
35
35
+
// If no specific pattern matches, return a generic message
36
36
+
return `tar command failed: ${errorMessage}`
37
37
+
}
38
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
24
-
// Include stderr in error message for better debugging
25
25
-
const errorMsg = stderr.trim() || `${tarCmd} command failed with code ${code}`
57
57
+
// Normalize error message for consistent cross-platform behavior
58
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
22
-
assert.match(
23
23
-
(error as Error).message,
24
24
-
/tar command failed|Failed to extract|incorrect header check|Error opening archive/,
25
25
-
)
22
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
46
-
/No files extracted from archive|tar command failed|Error opening archive/,
46
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
70
-
/No files extracted from archive|tar command failed|Error opening archive/,
70
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
83
-
/tar command failed|Failed to open/,
83
83
+
/tar command failed: File not found/,
84
84
)
85
85
})
86
86