Improve error handling and cleanup in shell functions (#10116)

Refactored various shell functions to add more robust error handling by redirecting stderr to /dev/null and using '|| true' to prevent script failures. Enhanced npm cache cleanup to remove both _cacache and _logs directories, and improved reliability of version and keyring extraction commands. These changes increase script resilience and prevent unnecessary errors from halting execution.
This commit is contained in:
CanbiZ (MickLesk)
2025-12-18 18:38:08 +01:00
committed by GitHub
parent e0e7aa94e8
commit c1ef6d7c51
2 changed files with 14 additions and 16 deletions
+3 -5
View File
@@ -815,12 +815,10 @@ cleanup_lxc() {
xargs -0 -n1 truncate -s 0 2>/dev/null || true
fi
# Node.js npm
# Node.js npm - directly remove cache directory
# npm cache clean/verify can fail with ENOTEMPTY errors, so we skip them
if command -v npm &>/dev/null; then
npm cache verify &>/dev/null || true
# Directly remove cache directory instead of using npm cache clean
# which can fail with ENOTEMPTY errors
rm -rf /root/.npm/_cacache 2>/dev/null || true
rm -rf /root/.npm/_cacache /root/.npm/_logs 2>/dev/null || true
fi
# Node.js yarn
if command -v yarn &>/dev/null; then $STD yarn cache clean || true; fi