Skip to content

fix(release): harden stale-branch fallback error handling (review follow-up)#169

Merged
derekmisler merged 3 commits into
mainfrom
fix/release-absolute-path-bug
May 4, 2026
Merged

fix(release): harden stale-branch fallback error handling (review follow-up)#169
derekmisler merged 3 commits into
mainfrom
fix/release-absolute-path-bug

Conversation

@docker-agent
Copy link
Copy Markdown
Contributor

Context

Follow-up to #168 (now merged). Addresses three findings from the PR review:


🟡 Fix 1 (NOTABLE): deleteRef error now propagated unless it's a 404 race

Before: The catch {} block silently swallowed all deleteRef errors, so createRef was called unconditionally even if deletion failed for a non-race reason (permissions, transient network), potentially leaving the branch in an inconsistent state with no useful error.

After: deleteRef errors are captured. A 404 is treated as a race-condition success (the branch is already gone) and createRef proceeds. Any other status throws a contextual error that includes the deleteRef status/message and the original updateRef error, so the operator knows exactly what happened:

Failed to delete stale branch "release-staging/v1.4.4" before recreating it
(deleteRef status 403: Must have admin rights). Original force-update error: Reference already exists

🔵 Fix 2 (MINOR): Explicit working-directory on the release step

Added working-directory: ${{ github.workspace }} to the Create release commit with pinned refs step so the CWD assumption that makes find dist/ -type f correct is explicit, not implicit.


🔵 Fix 3 (MINOR): Narrowed else if (status === 422) guard

Before: Any 422 from updateRef that wasn't "Reference does not exist" would silently trigger delete+recreate, masking unrelated errors (invalid ref name, protected ref, etc.).

After: The delete+recreate path only fires on "Reference already exists". All other 422s are re-thrown unchanged.


Tests

Replaced the two original stale-branch tests with four targeted cases:

  • 'Reference already exists' 422 → triggers delete+recreate ✓
  • Unknown 422 → re-thrown, no delete/createRef called ✓
  • deleteRef returns 404 (race) → createRef still runs ✓
  • deleteRef returns non-404 → wrapped error re-thrown, createRef not called ✓

All 34 unit tests pass. TypeScript type-check passes.

@docker-agent docker-agent requested a review from a team as a code owner May 4, 2026 20:10
@docker-agent docker-agent requested a review from derekmisler May 4, 2026 20:10
derekmisler
derekmisler previously approved these changes May 4, 2026
Three changes from code review of PR #168:

1. [NOTABLE] Capture deleteRef error; only swallow 404 (race-condition
   concurrent deletion).  All other deleteRef failures are now wrapped
   with context linking back to the original updateRef error and
   re-thrown so createRef is never called blindly.

2. [MINOR] Add `working-directory: ${{ github.workspace }}` to the
   'Create release commit with pinned refs' step, making the CWD
   assumption explicit rather than relying on the GitHub Actions
   default.

3. [MINOR] Narrow the `else if (status === 422)` stale-branch path to
   only fire when GitHub returns 'Reference already exists'.  Any other
   422 (invalid ref name, permissions, etc.) is now re-thrown unchanged
   instead of triggering a silent delete+recreate.

Tests updated accordingly: replace the two original stale-branch tests
with four targeted cases covering the narrowed trigger condition, the
re-throw path for unknown 422s, the 404 race-condition pass-through,
and the non-race deleteRef failure wrap-and-rethrow. All 34 unit tests
pass.

Assisted-By: docker-agent
@docker-agent docker-agent dismissed derekmisler’s stale review May 4, 2026 20:12

The merge-base changed after approval.

@docker-agent docker-agent force-pushed the fix/release-absolute-path-bug branch from e3e7579 to a127e30 Compare May 4, 2026 20:12
Copy link
Copy Markdown
Contributor Author

@docker-agent docker-agent left a comment

Choose a reason for hiding this comment

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

Assessment: 🟢 APPROVE

All three targeted fixes (narrowed 422 guard, structured deleteRef error propagation, explicit working-directory) are correctly implemented. CI is green (13/13 checks). Two minor observations noted as inline comments — neither blocks merge.

Comment thread src/signed-commit/signed-commit.ts
Comment thread src/signed-commit/signed-commit.ts
F1: Document that force:true hard-resets the target branch to baseRef
HEAD, calling out the footgun for long-lived branches.

F2: Pass { cause: deleteErr } to the wrapped Error thrown on non-404
deleteRef failures so Node error chaining preserves the original stack.

Assisted-By: docker-agent
@derekmisler derekmisler enabled auto-merge (squash) May 4, 2026 20:31
@derekmisler derekmisler merged commit 79e3352 into main May 4, 2026
14 checks passed
@derekmisler derekmisler deleted the fix/release-absolute-path-bug branch May 4, 2026 20:32
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.

2 participants