Skip to content

GH#2955: Replace blanket 2>/dev/null with explicit file checks in shell-env.sh#3003

Merged
marcusquinn merged 1 commit intomainfrom
bugfix/shell-env-quality-debt-2955
Mar 6, 2026
Merged

GH#2955: Replace blanket 2>/dev/null with explicit file checks in shell-env.sh#3003
marcusquinn merged 1 commit intomainfrom
bugfix/shell-env-quality-debt-2955

Conversation

@marcusquinn
Copy link
Owner

Summary

  • Replaces all remaining grep ... 2>/dev/null patterns in setup-modules/shell-env.sh with explicit [[ -f ]] file existence guards or removes the suppression where file existence is already guaranteed by prior logic
  • Prevents masking of permission errors and other non-file-not-found failures while maintaining correct behaviour for missing files

Changes (8 locations)

Lines Fix Rationale
207/209/211 Removed 2>/dev/null bash_files array built from [[ -f ]] checks
341 Removed 2>/dev/null $zsh_rc existence verified by early return
354 Removed 2>/dev/null Iterating over existence-checked bash_files
429 Removed 2>/dev/null File created at lines 423-425 if missing
696 Added [[ -f "$rc_file" ]] guard get_all_shell_rcs may return non-existent paths on Linux
704 Added [[ -f "$fish_config" ]] guard Fish config may not exist
737 Removed 2>/dev/null File created at lines 732-733 if missing
771 Removed redundant 2>/dev/null Already has [[ -f "$rc_file" ]] guard
802 Removed 2>/dev/null $tabby_config existence checked at line 800

Verification

  • ShellCheck: zero violations
  • All remaining 2>/dev/null usages are legitimate (platform command availability, intentional launchctl suppression)

Closes #2955

…nv.sh

Address quality-debt from PR #2937 review feedback (GH#2955).

Replace all remaining grep 2>/dev/null patterns with either:
- Removal (when file existence is already guaranteed by prior logic)
- Explicit [[ -f ]] guards (when the file may not exist)

This prevents masking permission errors and other non-file-not-found
failures while maintaining correct behaviour for missing files.
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the robustness and clarity of shell scripts by replacing generic error suppression with more explicit and context-aware file existence checks. The changes ensure that potential issues like permission errors are not silently ignored, leading to more reliable script execution and easier debugging.

Highlights

  • Improved Error Handling: Replaced blanket 2>/dev/null error suppression with explicit file existence checks ([[ -f ]]) in setup-modules/shell-env.sh to prevent masking of permission errors and other non-file-not-found failures.
  • Refined File Existence Checks: Removed redundant error suppression where file existence was already guaranteed by prior logic, making the script more precise and robust.
Changelog
  • setup-modules/shell-env.sh
    • Removed 2>/dev/null from grep commands at lines 207, 209, and 211, as bash_files array already verifies file existence.
    • Removed 2>/dev/null from grep command at line 341, as $zsh_rc existence is verified earlier.
    • Removed 2>/dev/null from grep command at line 354, as bash_files array already verifies file existence.
    • Removed 2>/dev/null from grep command at line 429, as the file is created if missing at lines 423-425.
    • Added [[ -f "$rc_file" ]] guard to grep command at line 696, as get_all_shell_rcs may return non-existent paths.
    • Added [[ -f "$fish_config" ]] guard to grep command at line 704, as the Fish config file may not exist.
    • Removed 2>/dev/null from grep command at line 737, as the file is created if missing at lines 732-733.
    • Removed redundant 2>/dev/null from grep command at line 771, as an [[ -f "$rc_file" ]] guard is already present.
    • Removed 2>/dev/null from grep command at line 802, as $tabby_config existence is checked at line 800.
Activity
  • No activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 6, 2026

Warning

Rate limit exceeded

@marcusquinn has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 18 minutes and 9 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 639cb0c0-80ca-46b8-af6e-ec23350a8094

📥 Commits

Reviewing files that changed from the base of the PR and between 97489d7 and 79b58fe.

📒 Files selected for processing (1)
  • setup-modules/shell-env.sh
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bugfix/shell-env-quality-debt-2955

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

github-actions bot commented Mar 6, 2026

🔍 Code Quality Report

�[0;35m[MONITOR]�[0m Code Review Monitoring Report

�[0;34m[INFO]�[0m Latest Quality Status:
SonarCloud: 0 bugs, 0 vulnerabilities, 108 code smells

�[0;34m[INFO]�[0m Recent monitoring activity:
Fri Mar 6 16:30:36 UTC 2026: Code review monitoring started
Fri Mar 6 16:30:36 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 108

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 108
  • VULNERABILITIES: 0

Generated on: Fri Mar 6 16:30:39 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 6, 2026

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request does a great job of systematically replacing blanket 2>/dev/null error suppression with more explicit file existence checks in setup-modules/shell-env.sh. This is a valuable improvement that prevents masking potential issues like permission errors while correctly handling expected cases like missing files. The changes are logical and well-documented in the PR description. The suggested pattern for grep -c was not included as it could lead to issues with arithmetic expansion when grep -c finds no matches, printing '0' and exiting with status 1, which would then be concatenated with the '0' from || echo 0. This conflicts with the robustness principles for arithmetic operations outlined in Rule 2, which advocates for using parameter expansion (e.g., ${var:-0}) to handle potentially empty or unexpected command substitution results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

quality-debt: setup-modules/shell-env.sh — PR #2937 review feedback (medium)

1 participant