Skip to content

refactor: add Client::prepare_request and avoid unneeded Result#2124

Closed
katrinafyi wants to merge 7 commits into
lycheeverse:masterfrom
rina-forks:split-check
Closed

refactor: add Client::prepare_request and avoid unneeded Result#2124
katrinafyi wants to merge 7 commits into
lycheeverse:masterfrom
rina-forks:split-check

Conversation

@katrinafyi

@katrinafyi katrinafyi commented Apr 2, 2026

Copy link
Copy Markdown
Member

First, this PR splits the old Client::check into Client::prepare_request and Client::check_prepared_request (while keeping the old check signature for backwards compat). prepare_request is a new function which centralises any "pre-check transformations". This means remaps can be done once in Client::prepare_request and re-used for both cache key and link checking. This also means we avoid weird cases like "what if cache_key is None" - this should never happen because if cache_key is None, then that link is already invalid.

Second, this PR tightens up some unneeded Result. I found that Client::check would only return Err in two cases: remap failure, and a rare insecure check error. After this change, remap errors are in Client::check_prepared_request, leaving the insecure http error in Client::check_prepared_request. I just tweak this one case so the check_prepared_request can unconditionally return Response. I think this is a bit neater and avoids the need for check_url in check.rs.

Follow-up to #2109 (review). Prompted by #2123 (comment).

@katrinafyi

Copy link
Copy Markdown
Member Author

78f4ad0 changes the output for remaps leading to invalid URLs.

old, split across log message and link checking error:

 [ERROR] Error checking URL https://example.com/: Invalid remap pattern: the result `invalid/` is not a valid URL
Issues found in 1 input. Find details below.

[stdin]:
[ERROR] https://example.com/ (at 1:1) | The given URI is invalid, check URI syntax: https://example.com/

🔍 1 Total (in 1ms) 🔗 1 Unique ✅ 0 OK 🚫 1 Error

new:

[stdin]:
 [ERROR] https://example.com/ (at 1:1) | Invalid remap: the result `invalid/` is not a valid URL. Check remap syntax

🔍 1 Total (in 2ms) 🔗 1 Unique ✅ 0 OK 🚫 1 Error

@katrinafyi

Copy link
Copy Markdown
Member Author

abandoning because this isn't the right approach. instead of a new function on client, we should make a new struct Remapper/Filter or even out this into the request chain.

the unneeded Result refactor is worth landing in a separate pr

@katrinafyi katrinafyi closed this Apr 13, 2026
katrinafyi added a commit to rina-forks/lychee that referenced this pull request Apr 15, 2026
this means that the Err case of `Client::check` will only happen due to
remap failures. this means the error cases we have to handle are much
clearer.

this commit re-lands this refactor which was previously part of
lycheeverse#2124. there's a bit more
context in that PR.
thomas-zahner pushed a commit to rina-forks/lychee that referenced this pull request Apr 20, 2026
this means that the Err case of `Client::check` will only happen due to
remap failures. this means the error cases we have to handle are much
clearer.

this commit re-lands this refactor which was previously part of
lycheeverse#2124. there's a bit more
context in that PR.
thomas-zahner pushed a commit that referenced this pull request Apr 20, 2026
…lt (#2140)

this means that the Err case of `Client::check` will only happen due to
remap failures. this means the error cases we have to handle are much
clearer.

this commit re-lands this refactor which was previously part of
#2124. there's a bit more
context in that PR.
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.

1 participant