docs(#181): add shell return-vs-exit correctness rule to AGENTS.md#504
docs(#181): add shell return-vs-exit correctness rule to AGENTS.md#504fullsend-ai-coder[bot] wants to merge 1 commit into
Conversation
Add a Shell scripting section with guidance on `return` vs `exit` context in executed scripts. The review agent will now flag top-level `return` outside a function body in executed scripts as a medium-severity correctness finding.
|
🤖 Finished Review · ✅ Success · Started 3:23 PM UTC · Completed 3:30 PM UTC |
Review — commentPR: #504 — SummaryThis PR adds a well-structured "Shell scripting" section to AGENTS.md, implementing the exact text proposed in issue #181. The change is properly authorized (linked issue with The review instruction itself — flag top-level Findings1.
|
|
|
||
| ## Shell scripting | ||
|
|
||
| ### `return` vs `exit` in executed scripts |
There was a problem hiding this comment.
[medium] technical-accuracy
The phrase "hard error" is misleading. In bash, a top-level return in an executed script produces an error message with exit status 2, but execution continues past the return line unless set -e is active. Without set -e, the guard silently fails and execution falls through (silent wrong behavior), which is arguably worse than an abort. The documentation implies the script always halts.
Suggested fix: Reword to: "return at the top level of an executed script produces a non-fatal error in bash — it prints a diagnostic but execution continues past it. Under set -e (or set -euo pipefail), the non-zero exit status triggers an immediate abort. Without set -e, the guard silently fails and execution falls through."
|
|
||
| ## Shell scripting | ||
|
|
||
| ### `return` vs `exit` in executed scripts |
There was a problem hiding this comment.
[low] technical-accuracy
The abort behavior is attributed to set -euo pipefail as a unit, but only -e (errexit) is relevant. The -u (nounset) and -o pipefail flags do not contribute to this mechanism.
Suggested fix: Say "under set -e" or add a parenthetical clarifying that -e is the specific flag that triggers the abort.
|
|
||
| ## Shell scripting | ||
|
|
||
| ### `return` vs `exit` in executed scripts |
There was a problem hiding this comment.
[low] technical-accuracy
The claim about return behavior is bash-specific but stated as universal. In POSIX sh (dash), return at top level of an executed script silently behaves like exit — no error, no diagnostic. Adding "In bash," as a qualifier would improve precision.
Suggested fix: Add "In bash," at the start of the sentence, or note the shell-dependent behavior.
Add a Shell scripting section with guidance on
returnvsexitcontext in executed scripts. The review agent will now flag top-levelreturnoutside a function body in executed scripts as a medium-severity correctness finding.Closes #181
Post-script verification
agent/181-shell-return-exit-rule)b776cf6006a12016eaa21412dc65a3001100e801..HEAD)