fix: Forgejo updater - structured error handling, ZIP prefix stripping, auth fixes #2

Merged
crashmedia merged 1 commit from fix/forgejo-updater into main 2026-05-29 04:11:25 +00:00
Owner

Summary

Fixes 3 critical bugs in the Forgejo updater that cause silent failures during updates.

Bug Fixes

Bug 1: Silent HTTP Error Handling

Before: makeForgejoRequest() returned false for ALL non-200 responses, losing error details. A 401 auth failure was indistinguishable from a 404 or 500 error.

After: Returns structured error info [success, error, http_code, body] with human-readable messages:

  • 401: "Authentication failed — check your Forgejo token"
  • 403: "Access denied — token may lack repo permissions"
  • 404: "Not found"
  • 429: "Rate limited — try again later"
  • 5xx: "Server error" with automatic retry

Bug 2: ZIP Archive Prefix Not Stripped

Before: Forgejo ZIP archives contain files with a root directory prefix (e.g., crashmedia-Arctic_Wolves-abc123/file.php). The updater didn't strip this prefix, causing files to be extracted to the wrong location.

After: downloadAndExtractArchive() detects the common root prefix and strips it before extraction.

Bug 3: Auth Headers & Redirect Handling

Before: makeForgejoRequest() did not follow redirects, causing auth failures on redirect chains.

After: Added CURLOPT_FOLLOWLOCATION and CURLOPT_MAXREDIRS to all API requests.

Additional Improvements

  • Automatic retries: Transient network errors (timeout, connection refused) retry up to 2 times
  • Rate limit backoff: HTTP 429 gets a 3-second delay between retries
  • 5xx retries: Server errors are retried automatically
  • Archive diagnostics: cURL errors and HTTP status codes are logged for archive downloads
  • Contextual error messages: checkForUpdates() and applyUpdates() now include HTTP status codes and context

Testing

  • PHP syntax: balanced braces (291/291) and parentheses (595/595) verified
  • No escaped dollar signs or syntax issues
  • All existing error paths preserved and enhanced
## Summary Fixes 3 critical bugs in the Forgejo updater that cause silent failures during updates. ## Bug Fixes ### Bug 1: Silent HTTP Error Handling **Before:** `makeForgejoRequest()` returned `false` for ALL non-200 responses, losing error details. A 401 auth failure was indistinguishable from a 404 or 500 error. **After:** Returns structured error info `[success, error, http_code, body]` with human-readable messages: - **401**: "Authentication failed — check your Forgejo token" - **403**: "Access denied — token may lack repo permissions" - **404**: "Not found" - **429**: "Rate limited — try again later" - **5xx**: "Server error" with automatic retry ### Bug 2: ZIP Archive Prefix Not Stripped **Before:** Forgejo ZIP archives contain files with a root directory prefix (e.g., `crashmedia-Arctic_Wolves-abc123/file.php`). The updater didn't strip this prefix, causing files to be extracted to the wrong location. **After:** `downloadAndExtractArchive()` detects the common root prefix and strips it before extraction. ### Bug 3: Auth Headers & Redirect Handling **Before:** `makeForgejoRequest()` did not follow redirects, causing auth failures on redirect chains. **After:** Added `CURLOPT_FOLLOWLOCATION` and `CURLOPT_MAXREDIRS` to all API requests. ## Additional Improvements - **Automatic retries**: Transient network errors (timeout, connection refused) retry up to 2 times - **Rate limit backoff**: HTTP 429 gets a 3-second delay between retries - **5xx retries**: Server errors are retried automatically - **Archive diagnostics**: cURL errors and HTTP status codes are logged for archive downloads - **Contextual error messages**: `checkForUpdates()` and `applyUpdates()` now include HTTP status codes and context ## Testing - PHP syntax: balanced braces (291/291) and parentheses (595/595) verified - No escaped dollar signs or syntax issues - All existing error paths preserved and enhanced
Bug 1: makeForgejoRequest() now returns structured error info
  (success, data, error, http_code) instead of silently returning false
  for ALL non-200 responses. Includes human-readable error messages for
  common HTTP codes (401, 403, 404, 429, 5xx).

Bug 2: downloadAndExtractArchive() now detects and strips the root
  directory prefix that Forgejo adds to ZIP archives.
  e.g. crashmedia-Arctic_Wolves-abc123/file.php -> file.php

Bug 3: Auth headers are now properly forwarded through redirects in
  makeForgejoRequest() (CURLOPT_FOLLOWLOCATION + CURLOPT_MAXREDIRS).
  Archive download also logs cURL errors for better diagnostics.

Additional improvements:
- Automatic retries on transient network errors (timeout, connection refused)
- Rate limit (429) backoff with 3s delay between retries
- 5xx server error retries
- Descriptive error messages in checkForUpdates() and applyUpdates()
  that include HTTP status codes and human-readable context
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
crashmedia/Arctic_Wolves!2
No description provided.