Skip to content

Commit 5a19e49

Browse files
committed
fix: add type-safe error handling to install scripts
Signed-off-by: leocavalcante <leo@cavalcante.dev>
1 parent e385365 commit 5a19e49

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

postinstall.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ function main() {
7878
copyFileSync(sourcePath, targetPath)
7979
successes.push(file)
8080
console.log(` Installed: ${file}`)
81-
} catch (error) {
81+
} catch (err) {
82+
const error = err instanceof Error ? err : new Error(String(err))
8283
const message = getErrorMessage(error, file, targetPath)
8384
failures.push({ file, message })
8485
console.error(` Failed: ${file} - ${message}`)

preuninstall.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ function main() {
5151
console.log(` Removed: ${file}`)
5252
removedCount++
5353
} catch (err) {
54-
console.error(` Warning: Could not remove ${file}: ${err.message}`)
54+
const message = err instanceof Error ? err.message : String(err)
55+
console.error(` Warning: Could not remove ${file}: ${message}`)
5556
}
5657
}
5758
}

0 commit comments

Comments
 (0)