Skip to content

fix(feed): import valid OPML feeds when some links are invalid - #291

Merged
0x2E merged 1 commit into
mainfrom
fix/opml-import-partial-failure
Nov 23, 2026
Merged

0x2E merged 1 commit into
mainfrom
fix/opml-import-partial-failure

Conversation

@0x2E

@0x2E 0x2E commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Summary

One dead link in an OPML file (usually a domain whose DNS lookup fails) made POST /api/feeds/batch reject the whole import with 400 "invalid link". Now every link is checked on its own, so the valid feeds get imported and each failed link is listed with the reason.

 batchCreateFeeds
   bind body                      # still 400 if malformed, now incl. items missing required fields (dive)
-  for each feed: ValidateRequestURL → first failure aborts with 400
+  validate all links concurrently (limit 8, 20s overall budget)
+  invalid → errors: "invalid URL <link>: <reason>"
   store.BatchCreateFeeds(valid)  # still reports "duplicate feed: <link>"
   200 {created, failed, errors}
  • The create, update and validate endpoints now include the reason: invalid URL: <reason>. httpc.ValidateRequestURL no longer adds its own invalid url: prefix, so the reason is not repeated.
  • Import dialog: when the import finishes, the dialog shows a result view instead of toasts. The view has a status icon (all imported / partial / all failed), the counts, and every failed link with its reason. The dialog can't be closed while the request is still running, so a late response can't bring back a stale result view.
  • docs/api-conventions.md explains why the batch endpoint imports what it can and reports the rest.

Evidence

  • Before: importing an OPML that contained https://blog.long-gone.invalid/feed.xml → 400 {"error":"invalid link"}, 0 feeds imported.
    After: the same import → 200, the valid feeds are imported, and the dialog lists:

    invalid URL https://blog.long-gone.invalid/feed.xml: resolve host: lookup blog.long-gone.invalid: no such host
    invalid URL ftp://files.example.com/rss.xml: unsupported url scheme: ftp
    invalid URL http://localhost:9000/rss: private host is not allowed
    duplicate feed: http://192.0.2.10/alive.xml
    
  • New tests in feed_batch_test.go, all offline (TEST-NET IPs and .invalid domains):

    • Mixed batch: the valid feeds are imported and the invalid/duplicate ones are reported.
    • A batch where every link is invalid returns 200.
    • Validation errors follow input order.
    • A malformed body returns 400.
    • The single-feed endpoints include the reason in the error.

    Also ran -race and a no-network run (unshare -rn).

  • Stalled DNS, tested with a resolver that never answers (130 stalled domains + 1 valid feed):

    • Before the budget: the client got an empty response after about 34s, but the valid feed had already been committed.
    • After: 200 in 20s, created=1 failed=130, every stalled link reported as i/o timeout.
  • Checked in the browser (light and dark mode):

    • Imports that fully succeed, partly fail, and fully fail.
    • X, Cancel, Esc and clicking the overlay can't close the dialog during an import.
    • The dialog resets after it is reopened.
    • An unreachable backend shows an error toast, and the dialog can still be closed.
  • ./scripts.sh test-backend and ./scripts.sh test-frontend pass.

Merge Danger

Door: two-way

Revert restores the old behavior. Nothing is migrated or stored differently.

Blast Radius: API

  • API clients calling POST /api/feeds/batch used to get 400 when any link was invalid. Now they get 200 and the invalid links are in errors.
  • A batch item missing group_id, name or link used to slip through. Now the whole request returns 400.
  • The error text from create, update and validate changed from invalid link / invalid url to invalid URL: <reason>.
  • The reason includes the raw resolver error, and that is visible to the signed-in user. Fusion is single-user, so this is acceptable.

Closes #261 (same root cause as #285).

🤖 Generated with Claude Code

A single link failing URL validation (typically a dead domain whose DNS
lookup fails) made POST /api/feeds/batch return 400 "invalid link", so
nothing was imported and the user could not tell which link or why.

- Batch create validates each link independently. Invalid links are
  skipped and reported in `errors` as `invalid URL <link>: <reason>`,
  next to the existing `duplicate feed: <link>`; the rest is imported.
  Only a malformed body (including items missing required fields) is 400.
- Validation runs with bounded concurrency and a 20s overall budget, so
  many stalled DNS lookups cannot push the request past the server write
  timeout while the valid feeds still get committed.
- Create, update and validate report the reason too: `invalid URL: <reason>`.
- The OPML import dialog ends on a result view with a status icon, the
  counts and every failed link with its reason, instead of toasts. It
  cannot be closed while the import is in flight.

BREAKING CHANGE: POST /api/feeds/batch no longer returns 400 when some
links are invalid; it returns 200 and lists them in `errors`.

Closes #261

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@0x2E
0x2E merged commit ddacf01 into main Nov 23, 2026
2 checks passed
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.

[FR] Improve error message for invalid feeds when importing OPML file

1 participant