-
Notifications
You must be signed in to change notification settings - Fork 212
Display "Go to latest stable" for pre-release #1045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display "Go to latest stable" for pre-release #1045
Conversation
src/web/rustdoc.rs
Outdated
let is_prerelease = semver::Version::parse(&version) | ||
// should be impossible unless there is a bug in match_version | ||
.map_err(|_| Nope::InternalServerError)? | ||
.is_prerelease(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is true, we allow exact matches before checking semver:
Line 333 in fb06f95
// first check for exact match, we can't expect users to use semver in query |
let is_prerelease = semver::Version::parse(&version) | |
// should be impossible unless there is a bug in match_version | |
.map_err(|_| Nope::InternalServerError)? | |
.is_prerelease(); | |
// If this is an exact match (not a valid semver), assume it's not a stable version. | |
let is_prerelease = semver::Version::parse(&version).unwrap_or(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you're right. But the suggested change won't work, because then GET /sqlx/0.3
would be treated as a pre-release although the semver compatible version 0.3.5 would be returned.
I thought just parsing the Version here would be the least invasive change, but it seems like I'll have to get the actual version returned from the DB for the release serverd.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mhh, i looked at it again. The version
is actually guaranteed to be semver compatible, because in the case of an exact match the version is semver compatible (if not, the db contains an invalid semver version) and in the case of an inexact match rustdoc_html_server_handler
will redirect to the exact version.
Lines 303 to 310 in c444b63
// Redirect when the requested version isn't correct | |
MatchSemver::Semver((v, _)) => { | |
// to prevent cloudfront caching the wrong artifacts on URLs with loose semver | |
// versions, redirect the browser to the returned version instead of loading it | |
// immediately | |
return redirect(&name, &v, &req_path); | |
} | |
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't follow, response to your previous comment"0.3"
is a valid semver and would be parsed successfully.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not, the db contains an invalid semver version
Hmm ... I don't think we enforce semantic versioning in the database, we depend on cargo to do it for us. In principle a 500 is probably the right thing to do, but it seems a shame to return that when it's so easy to return the page with a different text instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you rather add a new Nope
variant for this case? I feel like in this case it should be fine to just return a 500. We do the same in the match_version
func
Lines 348 to 360 in c444b63
for version in versions.iter().filter(|(_, _, yanked)| !yanked) { | |
// in theory a crate must always have a semver compatible version, | |
// but check result just in case | |
let version_sem = Version::parse(&version.0).map_err(|_| { | |
log::error!( | |
"invalid semver in database for crate {}: {}", | |
name, | |
version.0 | |
); | |
Nope::InternalServerError | |
})?; | |
versions_sem.push((version_sem, version.1)); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, the Nope
error would just turn into 'InternalServerError', right? I think that would be useful after #1046 to print the log message automatically (in the from
impl) but other than that I don't think it buys us much.
fb06f95
to
60f801d
Compare
9a877de
to
cadd04e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with nits fixed
templates/rustdoc/header.html
Outdated
{%- set tooltip = "You are seeing a yanked version of the " ~ krate.name ~ "crate. Click here to go to latest version." -%} | ||
{%- set title = "This release has been yanked, go to latest version" -%} | ||
{%- elif is_prerelease -%} | ||
{%- set tooltip = "You are seeing a pre-release version of the " ~ krate.name ~ "crate. Click here to go to latest stable version." -%} | ||
{%- set title = "Go to latest stable release" -%} | ||
{%- else -%} | ||
{%- set tooltip = "You are seeing an outdated version of the " ~ krate.name ~ "crate. Click here to go to latest version." -%} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: grammar
{%- set tooltip = "You are seeing a yanked version of the " ~ krate.name ~ "crate. Click here to go to latest version." -%} | |
{%- set title = "This release has been yanked, go to latest version" -%} | |
{%- elif is_prerelease -%} | |
{%- set tooltip = "You are seeing a pre-release version of the " ~ krate.name ~ "crate. Click here to go to latest stable version." -%} | |
{%- set title = "Go to latest stable release" -%} | |
{%- else -%} | |
{%- set tooltip = "You are seeing an outdated version of the " ~ krate.name ~ "crate. Click here to go to latest version." -%} | |
{%- set tooltip = "You are seeing a yanked version of the " ~ krate.name ~ "crate. Click here to go to the latest version." -%} | |
{%- set title = "This release has been yanked, go to latest version" -%} | |
{%- elif is_prerelease -%} | |
{%- set tooltip = "You are seeing a pre-release version of the " ~ krate.name ~ "crate. Click here to go to the latest stable version." -%} | |
{%- set title = "Go to latest stable release" -%} | |
{%- else -%} | |
{%- set tooltip = "You are seeing an outdated version of the " ~ krate.name ~ "crate. Click here to go to the latest version." -%} |
cadd04e
to
e3b09c9
Compare
Thanks for working on this (and putting up with all my nits)! |
No problem :) The code is better that way and you're reviewing really fast 😄 👍 |
PR rust-lang#1045 introduced a small typo in the "go to latest version" tooltips where a space was missing after the crate name.
PR #1045 introduced a small typo in the "go to latest version" tooltips where a space was missing after the crate name.
closes #1044