Skip to content

fix(pixiv): migrate user/detail to pixivFetch helper for typed errors#1768

Open
Benjamin-eecs wants to merge 1 commit into
jackwener:mainfrom
Benjamin-eecs:fix/pixiv-typed-errors
Open

fix(pixiv): migrate user/detail to pixivFetch helper for typed errors#1768
Benjamin-eecs wants to merge 1 commit into
jackwener:mainfrom
Benjamin-eecs:fix/pixiv-typed-errors

Conversation

@Benjamin-eecs
Copy link
Copy Markdown
Contributor

Description

clis/pixiv/user.js and clis/pixiv/detail.js hand-rolled their own inline fetch in the pipeline evaluate block and threw raw Error on 401/403/404/5xx, surfacing code: UNKNOWN to agents instead of the typed AUTH_REQUIRED / COMMAND_EXEC that pixivFetch in clis/pixiv/utils.js provides and that the sibling commands illusts.js / download.js / search.js already use.

Migrate to func-style adapters that go through pixivFetch. Also add up-front numeric-ID validation matching the sibling pattern in illusts.js, so malformed IDs fail before hitting the network.

ranking.js is intentionally left for follow-up: it hits /ranking.php?format=json whose response shape is data.contents, not the data.body that pixivFetch returns, so the helper needs a small extension before the migration can land cleanly there.

Related issue: fixes #1767. Continues the typed-error / silent-sentinel sweep direction from #1611, #1631, #1634.

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 🌐 New site adapter
  • 📝 Documentation
  • ♻️ Refactor
  • 🔧 CI / build / tooling

Checklist

  • I ran the checks relevant to this PR
  • I updated tests or docs if needed
  • I included output or screenshots when useful

Screenshots / Output

Live before / after on this branch:

opencli pixiv user 999999999999 --format yaml (any nonexistent ID):

# before (main)
ok: false
error:
  code: UNKNOWN
  message: |-
    Error: User not found: 999999999999
        at <anonymous>:9:35

# after (this branch)
ok: false
error:
  code: COMMAND_EXEC
  message: 'User not found: 999999999999'

opencli pixiv detail 12345 --format yaml (404) same swap from UNKNOWN to COMMAND_EXEC. Happy paths opencli pixiv user 11 and opencli pixiv detail 99999999 continue to return populated rows on this branch.

New clis/pixiv/user.test.js and clis/pixiv/detail.test.js mirror the illusts.test.js shape and cover invalid id → CommandExecutionError, 401 → AuthRequiredError, 404 → CommandExecutionError, 500 → CommandExecutionError, and the happy-path row mapping. Full pixiv suite: 28/28 pass.

@Benjamin-eecs Benjamin-eecs changed the title fix(pixiv): migrate user/detail to pixivFetch helper for typed errors (fixes #1767) fix(pixiv): migrate user/detail to pixivFetch helper for typed errors May 27, 2026
@Benjamin-eecs Benjamin-eecs marked this pull request as ready for review May 27, 2026 07:47
Copilot AI review requested due to automatic review settings May 27, 2026 07:47
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Refactors Pixiv user and detail CLIs to use a shared fetch helper and adds Vitest coverage for input validation and HTTP error handling.

Changes:

  • Replaced inline browser/evaluate pipelines with func implementations using pixivFetch.
  • Added Vitest unit tests for pixiv/user and pixiv/detail (invalid IDs, auth failures, not-found, and success mapping).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
clis/pixiv/user.js Moves to func + pixivFetch and adds argument validation and mapping logic.
clis/pixiv/detail.js Moves to func + pixivFetch and adds argument validation and mapping logic.
clis/pixiv/user.test.js Adds tests for error handling and user profile field mapping/counting.
clis/pixiv/detail.test.js Adds tests for error handling and illustration detail field mapping.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread clis/pixiv/user.js
Comment on lines +42 to +44
illusts: typeof b.illusts === 'object' ? Object.keys(b.illusts).length : (b.illusts || 0),
manga: typeof b.manga === 'object' ? Object.keys(b.manga).length : (b.manga || 0),
novels: typeof b.novels === 'object' ? Object.keys(b.novels).length : (b.novels || 0),
Raw Error throws surfaced UNKNOWN code instead of AUTH_REQUIRED / COMMAND_EXEC.

Fixes jackwener#1767
@Benjamin-eecs Benjamin-eecs force-pushed the fix/pixiv-typed-errors branch from 0765192 to 4d8a70c Compare May 28, 2026 12:19
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.

[Bug]: pixiv user/detail/ranking throw raw Error instead of typed AuthRequiredError / CommandExecutionError

2 participants