Skip to content

Conversation

Copy link

Copilot AI commented Dec 15, 2025

Purpose

Authentication and permission errors in upload_dists were being caught but not surfaced with actionable details. Users saw generic failure messages without HTTP status codes, making debugging difficult in CI/CD environments.

Rationale

The existing error handling caught HTTPError exceptions but only logged generic messages like "failed to upload asset {file} to release {id}". Critical diagnostic information (HTTP status codes) was only in debug logs, not in the raised exception message.

Changes

Test Coverage:

  • Added parametrized tests for HTTP error codes: 401 (auth), 403 (forbidden), 400, 404, 429, 500, 503
  • Added test for partial upload failures (some succeed, some fail)
  • Added dedicated tests for authentication and permission errors
  • Tests verify error messages include file paths, release IDs, and HTTP status codes

Error Message Enhancement:

  • Extract HTTP status code from HTTPError.response.status_code
  • Append status code to error messages: "failed to upload asset dist/pkg.whl to release 123 (HTTP 401)"
  • Handle Response object boolean evaluation correctly (evaluates to False even when present)
# Before
raise AssetUploadError("failed to upload asset dist/pkg.whl to release 123")

# After  
raise AssetUploadError("failed to upload asset dist/pkg.whl to release 123 (HTTP 401)")

How did you test?

  • All 11 new unit tests pass
  • All 189 existing GitHub HVCS tests remain passing
  • Verified error messages include status codes for all error scenarios
  • Tested partial failure case where multiple files fail with different status codes

How to Verify

  1. Run unit tests: pytest tests/unit/semantic_release/hvcs/test_github.py -v
  2. Verify new tests pass: test_upload_dists_fails_*
  3. Confirm error messages include HTTP status codes in test output

PR Completion Checklist

  • Reviewed & followed the Contributor Guidelines

  • Changes Implemented & Validation pipeline succeeds

  • Commits follow the Conventional Commits standard
    and are separated into the proper commit type and scope (recommended order: test, build, feat/fix, docs)

  • Appropriate Unit tests added/updated

  • Appropriate End-to-End tests added/updated

  • Appropriate Documentation added/updated and syntax validated for sphinx build (see Contributor Guidelines)

Original prompt

Can you write unit tests for the github hvcs class that will capture the error cases of upload_dists as we ended up having an authentication error that did not bubble up to the user. Details of the issue are in: python-semantic-release#1395 and python-semantic-release/publish-action#77


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits December 15, 2025 00:20
Add unit tests to capture error cases in GitHub HVCS upload_dists method:
- Test authentication errors (401 Unauthorized)
- Test forbidden errors (403 Forbidden)
- Test various HTTP error codes (400, 404, 429, 500, 503)
- Test partial upload failures (some succeed, some fail)
- Test successful uploads
- Verify error messages contain file and release information

These tests address issues python-semantic-release#1395 and python-semantic-release/publish-action#77
where authentication errors did not bubble up clearly to users.

Co-authored-by: codejedi365 <17354856+codejedi365@users.noreply.github.com>
Enhance error handling in GitHub HVCS upload_dists method to include
HTTP status codes in error messages. This helps users quickly identify
authentication (401), permission (403), and other HTTP errors when
distribution uploads fail.

Changes:
- Capture HTTP status code from HTTPError response
- Include status code in error messages (e.g., "HTTP 401", "HTTP 403")
- Fix Response object boolean evaluation issue

Tests updated to verify error messages include status codes.

Co-authored-by: codejedi365 <17354856+codejedi365@users.noreply.github.com>
Copilot AI changed the title [WIP] Add unit tests for github hvcs upload_dists error handling test(hvcs): add unit tests for upload_dists error cases and improve error messages Dec 15, 2025
Copilot AI requested a review from codejedi365 December 15, 2025 00:27
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