fix(worker): surface EXPIRED_LINK / INVALID_LINK instead of UNKNOWN_ERROR#79
Merged
Merged
Conversation
…RROR
Two bugs were combining to mask real failures:
1. download_file treated any non-200 HEAD as INVALID_LINK, including the
4xx response that click.discord.com → GCS gives once the signed URL
has expired. The user's link looked fine when they pasted it; it just
timed out before the worker got to it.
2. process_package had `expected = ('EXPIRED_LINK')` — a string, not a
tuple, because the parens are grouping rather than building a tuple.
The substring check (`if expected not in current`) only recognized
EXPIRED_LINK; INVALID_LINK and any future codes got relabeled as
UNKNOWN_ERROR.
Net effect from the user's POV: they'd retry an expired link and see
'UNKNOWN_ERROR' three times before realizing they needed a fresh export.
Now:
- HEAD 4xx → EXPIRED_LINK (the common case for stale links).
- HEAD non-200 / wrong content-type → INVALID_LINK.
- Anything else → UNKNOWN_ERROR with the full traceback preserved.
- The expected-codes list is a real tuple containing both known codes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two interacting bugs were causing every link-download failure to surface as `UNKNOWN_ERROR`, including the very common case of a Discord link that expired before the worker picked it up.
Bug 1: download_file treated 4xx as `INVALID_LINK`
`click.discord.com` 302s to a Google Cloud Storage signed URL. Once the signature TTL is up (Discord exports expire fairly quickly), the GCS URL returns `HTTP 400`. The old code:
```python
if r.status_code != 200 or 'content-type' not in r.headers or 'application/octet-stream' not in r.headers['content-type']:
raise Exception('INVALID_LINK')
```
…raised `INVALID_LINK`, which was wrong — the link wasn't malformed, it was expired.
Bug 2: `process_package` masked everything except EXPIRED_LINK
```python
expected = ('EXPIRED_LINK') # ← this is a STRING, not a tuple!
if expected not in current:
current = 'UNKNOWN_ERROR'
```
Python tuples need a comma: `('EXPIRED_LINK',)`. The intended single-element tuple is just the bare string. The `in` check then accidentally did substring match on a single code — so even when the worker raised `INVALID_LINK`, the route relabeled it `UNKNOWN_ERROR`.
Fix
Verified against a real expired link
```
$ curl -sS -I -L "<user's example expired upn>"
HTTP/2 302 ← click.discord.com
location: https://storage.googleapis.com/discord-harvest-prd/.../package.zip?...
HTTP/2 400 ← GCS, signature expired
```
So `requests.head(link, allow_redirects=True).status_code` is `400` for an expired link → my new branch catches it and raises `EXPIRED_LINK`.
Frontend follow-up (separate)
The frontend's status-response type doesn't currently list `INVALID_LINK` as a possible `errorMessageCode` (only the four: UNKNOWN_PACKAGE_ID, UNKNOWN_ERROR, UNAUTHORIZED, EXPIRED_LINK). If we want the friendly "Link expired" copy to render for INVALID_LINK too, that's a one-line type widening in dumpus-app — happy to open it as a follow-up PR.
Test plan