Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions setup-modules/migrations.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ cleanup_deprecated_paths() {
cleanup_osgrep() {
local cleaned=false

# 0. Kill running osgrep processes first (MCP servers, indexers)
# These are Node.js processes already loaded in memory — removing the
# binary and data won't stop them, and they may try to rebuild indexes.
if pgrep -f 'osgrep' >/dev/null 2>&1; then
print_info "Killing running osgrep processes..."
pkill -f 'osgrep' 2>/dev/null || true
# Give processes a moment to exit gracefully
sleep 1
# Force-kill any stragglers
pkill -9 -f 'osgrep' 2>/dev/null || true
cleaned=true
fi
Comment on lines +82 to +90

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The use of 2>/dev/null and 2>&1 for blanket suppression of stderr violates the repository style guide (line 50) and general rules. Redirection of stdout (>/dev/null) is sufficient for pgrep to check for process existence without polluting the terminal. Additionally, using a more specific pattern for pkill -f (e.g., targeting the binary path or using word boundaries) is recommended to avoid accidentally matching the script's own path if it contains the string "osgrep".

Suggested change
if pgrep -f 'osgrep' >/dev/null 2>&1; then
print_info "Killing running osgrep processes..."
pkill -f 'osgrep' 2>/dev/null || true
# Give processes a moment to exit gracefully
sleep 1
# Force-kill any stragglers
pkill -9 -f 'osgrep' 2>/dev/null || true
cleaned=true
fi
if pgrep -f 'osgrep' >/dev/null; then
print_info "Killing running osgrep processes..."
pkill -f 'osgrep' || true
# Give processes a moment to exit gracefully
sleep 1
# Force-kill any stragglers
pkill -9 -f 'osgrep' || true
cleaned=true
fi
References
  1. 2>/dev/null is acceptable ONLY when redirecting to log files, not blanket suppression. (link)
  2. In shell scripts, avoid blanket suppression of errors with '2>/dev/null'. For 'declare -f', redirecting only stdout ('>/dev/null') is sufficient as it does not output to stderr, allowing potential syntax errors to remain visible.
  3. Avoid using '2>/dev/null' for blanket suppression of command errors in shell scripts to ensure that authentication, syntax, or system issues remain visible for debugging.
  4. In shell scripts with set -e, guard kill commands within cleanup traps with || true to prevent premature termination if the target process has already exited, ensuring subsequent cleanup commands are executed.


# 1. Uninstall npm package (global)
if command -v osgrep &>/dev/null; then
print_info "Removing osgrep npm package..."
Expand Down
Loading