Skip to content
Open
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
10 changes: 8 additions & 2 deletions regen-defs.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ for folder in $folders; do
stdout_file=$(mktemp)
stderr_file=$(mktemp)

# Cleanup on interruption
cleanup() {
rm "$stdout_file" "$stderr_file"
}
trap cleanup INT TERM

# Execute the command and capture stdout and stderr
uv run "$cpplint" $cmd > "$stdout_file" 2> "$stderr_file"
eval uv run "$cpplint" $cmd > "$stdout_file" 2> "$stderr_file"
ret_code=$?

# Count the number of lines in stdout
Expand All @@ -42,7 +48,7 @@ for folder in $folders; do
} > "$file"

# Clean up temporary files
rm "$stdout_file" "$stderr_file"
cleanup
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

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

The cleanup function is only called on successful completion of a loop iteration (line 51), but not when errors occur earlier. If uv run fails or if any operation between lines 23-48 causes the script to exit, the temporary files will not be cleaned up.

Additionally, the trap handler won't catch normal exit conditions (like the exit calls on lines 6 and 11). Consider:

  1. Adding EXIT to the trap signals: trap cleanup INT TERM EXIT
  2. Moving the trap setup earlier in the script to catch early exits

Note: If you add EXIT to the trap, you may need to prevent double-cleanup on line 51.

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think a command in between can cause termination of the entire script, and as mentioned trapping EXIT can get a bit messy.

done
cd ..
done