Improve 404 page for missing rustdoc resources - #3416
Conversation
Include an empty `recovery` Vec in the about handler's not-found page response. This ensures the response struct has the newly required `recovery` field and prevents missing-field errors after the page/template was extended.
Refactor JSON error response construction to avoid emitting an empty "links" array. The code now builds a base body with title and message and only inserts the "links" field if recovery links are non-empty. Also minor cleanup: clarified the NoResults comment and added braces around the Redirect match arm.
Refactor the match arm for AxumNope::Redirect in crates/bin/docs_rs_web/src/error.rs to a single-line expression calling redirect_with_policy(target, cache_policy). This is a formatting/clarity change only and does not alter behavior.
|
Thanks @syphar. Agreed. |
before I spend more time reviewing this:
I'm ok with people using AI for their contribution, if the author also reviewed & tested everything. |
Address review feedback on rust-lang#2568: clarify the contextual missing-page message and render the recovery links as pure-css action buttons instead of a plain bullet list. JSON error body structure is unchanged.
459832c to
2137e12
Compare
The error page title lives in a `div.container`, which is only centered on the page when the body sets the `centered` class. The error page doesn't, so the title was centered inside a box pinned to the left edge while the message and recovery links below centered against the full page width. Scope the container centering to the error page with an `error-header` class so the title lines up with the text below it, center the recovery links, and give them a small top gap so they read as part of the message rather than running into it.
|
Please add a GUI test then. :) |
|
Thanks for the suggestion. I added a GUI test in |
|
Hi @syphar @GuillaumeGomez. Just checking in. I added the GUI test in gui-tests/404.goml covering the contextual 404 title, message, and both recovery links, and it passes locally. One note on CI: the "rust linters" job is currently failing, but it looks unrelated to this PR — it's crashing with an internal compiler error while building the tokio dependency (rustc ICE in rustc_codegen_ssa), before it even reaches this crate's code. GUI_test, test, js linters, and both Docker builds are all green. Happy to re-push if a CI re-run doesn't clear it up. Let me know if there's anything else you'd like adjusted. |
|
I'm currently traveling, I can have a look next week. Yes, the compiler ICE is unrelated to your change. It's fixed in the new nightly compiler. |


Summary
Improves the error page shown when a requested rustdoc resource does not exist in an otherwise valid crate version.
Instead of displaying only a generic 404 page, the response now includes links to:
Fixes #2568.
Changes
ResourceNotFoundInVersionerror variant/latest/and pinned-version URLs when constructing recovery linksNon-goals
This PR intentionally does not:
These can be considered separately if desired.
Testing
AxumErrorPageinitializers updated