fix(formatters/markdown): stop leaking <error:> placeholder into output#2144
Open
tmchow wants to merge 3 commits intolycheeverse:masterfrom
Open
fix(formatters/markdown): stop leaking <error:> placeholder into output#2144tmchow wants to merge 3 commits intolycheeverse:masterfrom
tmchow wants to merge 3 commits intolycheeverse:masterfrom
Conversation
When lychee cannot parse a link into a URL, lychee-lib substitutes a placeholder Uri (scheme: "error") via RequestError::into_response. The markdown formatter always wraps the Uri in <>, so a malformed link in the input file surfaced as `<error:>` in the report -- burying the actual URL and error under markup noise (lycheeverse#2143). Detect the placeholder scheme ("error") and skip the <uri> segment when rendering. The status code, span, and underlying error details still carry enough information for the reader to find and fix the malformed link, without the misleading <error:> anchor. Fixes lycheeverse#2143
Addresses codex:review P3 feedback on PR lycheeverse#2144: the initial check suppressed the URI for any Uri with scheme 'error', which would also hide legitimate inputs like 'error:foo'. Narrow to exact sentinel match via Uri::as_str() == "error:" so the behavior only changes for the placeholder emitted by RequestError::into_response. Also add a regression test confirming that non-sentinel URIs with the 'error:' scheme still render their full <uri> segment.
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
When lychee encounters a link whose URL can't be parsed, the markdown stats formatter was leaking
<error:>into the report because the placeholder Uri constructed bylychee_lib::types::request_errorhas scheme"error"and the formatter always wraps the Uri in<…>. Addresses #2143.Why
RequestError::into_response(inlychee-lib/src/types/request_error.rs) constructs a syntheticResponsefor reporting purposes whenever a raw link can't be turned into a valid URL. It uses a singlestatic ERROR_URI: LazyLock<Uri> = LazyLock::new(|| Uri::try_from("error:").unwrap());as the placeholder, backed by theerror:scheme.The existing markdown formatter treated every response identically:
For the placeholder,
response.urirenders aserror:, so the output became:That's bad for two reasons:
<error:>looks like a clickable anchor pointing at an unresolvable custom scheme, and it visually overshadows the actual failing URL which now only lives in the| detailstail.Changes
lychee-bin/src/formatters/stats/markdown.rs:UNPARSEABLE_URI_SCHEME = "error", kept in lockstep withlychee-lib's placeholder (the comment points back atrequest_error.rsso it doesn't drift silently).markdown_responsenow branches: whenresponse.uri.scheme() == UNPARSEABLE_URI_SCHEME, it omits the<uri>segment and emits just* [STATUS]; the subsequent(at span)and| detailstail continue to render normally.Testing
test_markdown_response_unparseable_url_omits_uri_segmentdirectly exercises the placeholder path:ResponseBodywithUri::try_from("error:")(the same valueRequestError::into_responseemits).<error:>is not present in the output.* [ERROR]so downstream consumers still see the status code.(at 1:1)and the underlying malformed URL text survive in the details tail.cargo test --package lychee --bin lychee-> 78 passed, 0 failed.Fixes #2143
This contribution was developed with AI assistance (Claude Code).