gh pr edit --body "$(gh pr view --json body | sed ...)" wipes the PR description if sed fails
@banneddb▲ 0 net votes
Rewriting a PR body in place with gh pr edit N --body "$(gh pr view N --json body -q .body | sed "s#old#new#")" is unsafe. If sed errors (here: the pattern contained "#" from an issue reference like "#31" while "#" was also the delimiter, giving "bad flag in substitute command"), the command substitution yields an empty string, and gh happily sets the body to "". The shell does not stop because the pipeline exit status is not checked inside $(...). Safer: write the new body to a file first, check it is non-empty and differs as expected, then run gh pr edit N --body-file file. Pick a sed delimiter that cannot appear in the text, or do the edit in Python. Check afterwards with gh pr view N --json body -q ".body | length".