reactive-firewall / ymmv

Your Milage May Vary...
Other
0 stars 1 forks source link

Gather and standardize exit codes #7

Open reactive-firewall opened 3 days ago

reactive-firewall commented 3 days ago

While CEP-8 is a great start, the project could benefit from standardized exit codes.

reactive-firewall commented 3 days ago

@coderabbitai, please read all the source files in the project and extract all numerical return values and exit codes from both shell-scripts and python code. Additionally read CEP-8 focusing on it's impacts to exit codes. Then provide a detailed summary of the findings including an enumeration of the different exit codes.

coderabbitai[bot] commented 3 days ago

[!TIP] For best results, initiate chat on the files or code changes.

@reactive-firewall,

Here is a detailed summary of the numerical return values and exit codes extracted from the project's shell scripts, along with an analysis of their compliance with CEP-8 and its impact on exit codes.


Exit Codes Found in Shell Scripts:

  1. Exit Code 0:

    • Meaning: Success.
    • Usage:
      • Used to indicate successful completion of scripts.
      • Examples:
      • tests/test_aliases_config.bash:72: exit 0;
      • payload/Patch_MacOS_ARP.sh:18: exit 0;
      • payload/bin/printBanner.sh:516: exit 0;
      • payload/Setup/setup_lg_hub.bash:45: exit 0;
      • payload/Setup/update_homebrew.bash:155: exit 0
  2. Exit Code 1:

    • Meaning: General error.
    • Usage:
      • Often used in signal traps to indicate that the script was terminated due to an error.
      • Examples:
      • tests/test_plists.bash:73-78: Exits with code 1 upon receiving signals like SIGHUP, SIGTERM, etc.
      • payload/Setup/setup_TDR_Nova.bash:19: exit 1 when unzip fails.
      • payload/Setup/provision_mac.bash:11: exit 1; if sudo authentication fails.
  3. Exit Code 2:

    • Meaning: Misuse of shell built-ins (according to POSIX, but can be script-defined).
    • Usage:
      • Used to indicate specific errors, such as unzip test failures.
      • Examples:
      • payload/Setup/setup_TDR_Nova.bash:16: exit 2 if unzip test fails.
      • payload/Setup/setup_TDR_Nova.bash:24: exit 2; on specific error conditions.
      • Similar usage in other scripts like setup_TDR_vos_slickeq.bash and setup_bnet.bash.
  4. Exit Codes 3, 4, 5, 7, 8, 9:

    • Meaning: Custom exit codes, often used in signal traps.
    • Usage:
      • Assigned to EXIT_CODE variables but the actual exit command uses exit 1.
      • Examples:
      • tests/test_plists.bash:73-78: Sets EXIT_CODE to 3, 4, 5, 7, 8, 9 for different signals.
      • Similar patterns in other test scripts like test_pf_config.bash, test_git_config.bash.
  5. Exit Code 126:

    • Meaning: Command invoked cannot execute.

    • Usage:

      • Used to indicate missing prerequisites or commands that cannot be executed.
      • Examples:
      • tests/test_plists.bash:70: test -x $(command -v xmllint) || exit 126;
      • tests/test_cc_lines.bash:70-73: Checks for grep, curl, find, git, and exits with 126 if not found.
      • tests/test_bin_cmd_applist.bash:71-76: Similar checks for command existence.
    • Note: This usage aligns with your project's convention, as per the retrieved learning that exit code 126 indicates missing prerequisites.

  6. Exit Code 255:

    • Meaning: Exit status out of range or custom error code.
    • Usage:
      • Used to indicate severe errors or failures.
      • Examples:
      • tests/test_plists.bash:83: exit 255;
      • tests/test_git_config.bash:83: exit 255;
      • tests/test_bin_cmd_applist.bash:75: exit 255; if shlock cannot be hashed.

Exit Codes in Python Scripts:


Impact of CEP-8 on Exit Codes:

CEP-8 emphasizes adherence to POSIX standards for exit codes. According to POSIX and as outlined in CEP-8:

Analysis:


Recommendations:

  1. Update Signal Trap Exit Codes:

    • Modify signal traps to use the standard 128 + n exit codes.
      • For example:
      • SIGINT (2): exit 130
      • SIGTERM (15): exit 143
      • SIGHUP (1): exit 129
    • This ensures compliance with POSIX and makes the exit codes more meaningful.
  2. Replace Custom Exit Codes:

    • Review the necessity of custom exit codes 3, 4, 5, 7, 8, 9.
    • If specific error conditions need to be distinguished, document them clearly, or map them to standard exit codes.
  3. Avoid Using Exit Code 255:

    • Replace with exit 1 for general errors or a more specific standard exit code.
    • Ensure that exit codes remain within the 0-255 range and do not conflict with standard meanings.

Note on Retrieved Learnings:


Please let me know if you need assistance with implementing these recommendations or if you have any questions about the findings.

🔗 Analysis chain
🏁 Scripts executed The following scripts were executed for the analysis: Script: ```shell #!/bin/bash # Extract all numerical exit codes from shell scripts rg --type sh 'exit\s+([0-9]+)' -n # Extract numerical return values and sys.exit calls from Python files rg --type py 'return\s+([0-9]+)' -n rg --type py 'sys\.exit\s*\(\s*([0-9]+)\s*\)' -n # Fetch CEP-8 content for analysis curl -s https://gist.github.com/reactive-firewall/b7ee98df9e636a51806e62ef9c4ab161 ``` Length of output: 137165

🧠 Learnings used ``` Learnt from: reactive-firewall PR: reactive-firewall/multicast#110 File: docs/CI.md:32-32 Timestamp: 2024-09-17T06:40:42.918Z Learning: Reactive-firewall prefers to keep the word "own" in headings when emphasizing the reader's personal test. ``` --- ``` Learnt from: reactive-firewall PR: reactive-firewall/ymmv#0 File: :0-0 Timestamp: 2024-10-04T04:44:29.557Z Learning: Reactive-firewall prefers to include custom coding standards CEP-8 and CEP-5 for Python and Bash code respectively in code reviews. ``` --- ``` Learnt from: reactive-firewall PR: reactive-firewall/ymmv#0 File: :0-0 Timestamp: 2024-10-04T04:44:29.557Z Learning: Reactive-firewall prefers to include custom coding standards CEP-8 and CEP-5 for Python and Bash code respectively in code reviews. ``` --- ``` Learnt from: reactive-firewall PR: reactive-firewall/python-repo#75 File: .github/workflows/ossar.yml:20-31 Timestamp: 2024-09-09T00:05:09.229Z Learning: When reviewing security configurations, avoid suggesting the removal of duplicate security controls if doing so would violate the "Defence in Depth" principle, as per the user's preference. ``` --- ``` Learnt from: reactive-firewall PR: reactive-firewall/ymmv#0 File: :0-0 Timestamp: 2024-10-04T03:58:43.291Z Learning: Reactive-firewall prefers to include tests and documentation in the code review process and not exclude them from analysis. ``` --- ``` Learnt from: reactive-firewall PR: reactive-firewall/ymmv#0 File: :0-0 Timestamp: 2024-10-04T04:44:29.557Z Learning: Reactive-firewall prefers all bash files to start with an extensive disclaimer as per the link: https://gist.github.com/reactive-firewall/866b42d175ae3ebefcb2a5878b30ea17. ``` --- ``` Learnt from: reactive-firewall PR: reactive-firewall/multicast#110 File: docs/USAGE.md:66-66 Timestamp: 2024-09-17T03:38:28.677Z Learning: Reactive-firewall prefers to use "Caveat" as a heading instead of "Caution". ``` --- ``` Learnt from: reactive-firewall PR: reactive-firewall/multicast#118 File: tests/check_pip:92-197 Timestamp: 2024-09-24T01:03:10.574Z Learning: Reactive-firewall prefers defining functions before they are called in Bash scripts to avoid errors due to Bash's sequential interpretation. ``` --- ``` Learnt from: reactive-firewall PR: reactive-firewall/multicast#0 File: :0-0 Timestamp: 2024-09-18T03:06:53.911Z Learning: In this project, exit code 126 is used as the convention for indicating missing prerequisites in scripts. This convention comes from git hooks, and is compliant with [CEP-8](https://gist.github.com/reactive-firewall/b7ee98df9e636a51806e62ef9c4ab161). ```
reactive-firewall commented 2 days ago

@coderabbitai, an updated draft of CEP-8 has been posted with clarifications and new guidelines for exit-codes and style. This also impacts your learning ID: 65742d41-e218-4f97-b8f5-9733b83cf5bc

coderabbitai[bot] commented 2 days ago

[!TIP] For best results, initiate chat on the files or code changes.

@reactive-firewall,

Thank you for informing me about the updated draft of CEP-8 with the new guidelines for exit codes and style. I acknowledge that this impacts the learning with ID 65742d41-e218-4f97-b8f5-9733b83cf5bc. I will remove this learning to align with the latest guidelines.


🧠 Learnings used ``` Learnt from: reactive-firewall PR: reactive-firewall/multicast#110 File: docs/CI.md:32-32 Timestamp: 2024-10-08T21:59:30.537Z Learning: Reactive-firewall prefers to keep the word "own" in headings when emphasizing the reader's personal test. ``` --- ``` Learnt from: reactive-firewall PR: reactive-firewall/multicast#110 File: docs/CI.md:32-32 Timestamp: 2024-09-17T06:40:42.918Z Learning: Reactive-firewall prefers to keep the word "own" in headings when emphasizing the reader's personal test. ``` --- ``` Learnt from: reactive-firewall PR: reactive-firewall/ymmv#0 File: :0-0 Timestamp: 2024-10-04T04:44:29.557Z Learning: Reactive-firewall prefers to include custom coding standards CEP-8 and CEP-5 for Python and Bash code respectively in code reviews. ``` --- ``` Learnt from: reactive-firewall PR: reactive-firewall/ymmv#0 File: :0-0 Timestamp: 2024-10-08T21:59:30.537Z Learning: Reactive-firewall prefers to include custom coding standards CEP-8 and CEP-5 for Python and Bash code respectively in code reviews. ``` --- ``` Learnt from: reactive-firewall PR: reactive-firewall/ymmv#0 File: :0-0 Timestamp: 2024-10-08T21:59:30.537Z Learning: Reactive-firewall prefers to include custom coding standards CEP-8 and CEP-5 for Python and Bash code respectively in code reviews. ``` --- ``` Learnt from: reactive-firewall PR: reactive-firewall/ymmv#0 File: :0-0 Timestamp: 2024-10-08T21:59:27.171Z Learning: Reactive-firewall prefers to include custom coding standards CEP-8 and CEP-5 for Python and Bash code respectively in code reviews. ``` --- ``` Learnt from: reactive-firewall PR: reactive-firewall/ymmv#0 File: :0-0 Timestamp: 2024-10-04T04:44:29.557Z Learning: Reactive-firewall prefers to include custom coding standards CEP-8 and CEP-5 for Python and Bash code respectively in code reviews. ``` --- ``` Learnt from: reactive-firewall PR: reactive-firewall/python-repo#75 File: .github/workflows/ossar.yml:20-31 Timestamp: 2024-09-09T00:05:09.229Z Learning: When reviewing security configurations, avoid suggesting the removal of duplicate security controls if doing so would violate the "Defence in Depth" principle, as per the user's preference. ``` --- ``` Learnt from: reactive-firewall PR: reactive-firewall/python-repo#75 File: .github/workflows/ossar.yml:20-31 Timestamp: 2024-10-08T21:59:30.537Z Learning: When reviewing security configurations, avoid suggesting the removal of duplicate security controls if doing so would violate the "Defence in Depth" principle, as per the user's preference. ``` --- ``` Learnt from: reactive-firewall PR: reactive-firewall/multicast#0 File: :0-0 Timestamp: 2024-10-08T03:15:05.171Z Learning: For future reviews, remember that when drafting or updating CEP documents, it's important to adhere to the project's standard format and include all relevant sections such as Motivation, Detailed Explanation, Implementation Guidelines, Impact, and References. ```