codeflash-internal/js/cf-api/github/tests
HeshamHM28 6b12255143
[fix] handle label creation race condition and log errors to Sentry instead of throwing (#2265)
## Summary

- Fix race condition in `ensureLabelExists` where concurrent requests
both get a 404, then both try to create the label, causing an
"already_exists" validation error
- Add `isLabelAlreadyExistsError` helper function to properly detect
GitHub's 422 validation error for duplicate labels
- Change error handling from throwing to logging to Sentry, preventing
the entire PR creation flow from failing due to label issues
- Update tests to verify new Sentry logging behavior and race condition
handling

  ## Problem

  When multiple concurrent requests call `ensureLabelExists`:
  1. Both check if label exists → both get 404
  2. Both try to create the label
3. First succeeds, second fails with
`{"resource":"Label","code":"already_exists","field":"name"}`
4. This error was thrown and caused the entire suggest-pr-changes flow
to fail

  ## Solution

- Catch the `already_exists` error during label creation and silently
ignore it (label exists, which is the desired state)
- Log other errors to Sentry instead of throwing, so label issues don't
block PR creation
FIxes CF-1017
2026-01-20 20:05:36 +02:00
..
create-pr-from-diffcontents.unit.test.ts unit test 2025-11-07 10:54:43 -08:00
github-utils.unit.test.ts [fix] handle label creation race condition and log errors to Sentry instead of throwing (#2265) 2026-01-20 20:05:36 +02:00
slack_util.unit.test.ts Implement Tests for CF-API Flow (#1634) 2025-06-25 03:36:26 +05:30