Skip to content

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

Merged

Conversation

robinhundt
Copy link
Contributor

closes #1044

@jyn514 jyn514 added A-backend Area: Webserver backend S-waiting-on-review Status: This pull request has been implemented and needs to be reviewed labels Sep 13, 2020
Comment on lines 371 to 383
let is_prerelease = semver::Version::parse(&version)
// should be impossible unless there is a bug in match_version
.map_err(|_| Nope::InternalServerError)?
.is_prerelease();
Copy link
Member

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:

// first check for exact match, we can't expect users to use semver in query

Suggested change
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);

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

docs.rs/src/web/rustdoc.rs

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);
}
};

Copy link
Member

@jyn514 jyn514 Sep 13, 2020

Choose a reason for hiding this comment

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

I don't follow, "0.3" is a valid semver and would be parsed successfully. response to your previous comment

Copy link
Member

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.

Copy link
Contributor Author

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

docs.rs/src/web/mod.rs

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));
}

Copy link
Member

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.

@robinhundt robinhundt force-pushed the show-go-to-stable-for-pre-release branch from fb06f95 to 60f801d Compare September 13, 2020 16:45
@robinhundt robinhundt force-pushed the show-go-to-stable-for-pre-release branch 2 times, most recently from 9a877de to cadd04e Compare September 13, 2020 19:48
Copy link
Member

@jyn514 jyn514 left a 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

Comment on lines 187 to 193
{%- 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." -%}
Copy link
Member

Choose a reason for hiding this comment

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

nit: grammar

Suggested change
{%- 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." -%}

@robinhundt robinhundt force-pushed the show-go-to-stable-for-pre-release branch from cadd04e to e3b09c9 Compare September 13, 2020 19:59
@jyn514 jyn514 merged commit b2b7458 into rust-lang:master Sep 13, 2020
@jyn514
Copy link
Member

jyn514 commented Sep 13, 2020

Thanks for working on this (and putting up with all my nits)!

@robinhundt
Copy link
Contributor Author

No problem :) The code is better that way and you're reviewing really fast 😄 👍

robinhundt added a commit to robinhundt/docs.rs that referenced this pull request Oct 13, 2020
PR rust-lang#1045 introduced a small typo in the "go to latest version" tooltips
where a space was missing after the crate name.
jyn514 pushed a commit that referenced this pull request Oct 13, 2020
PR #1045 introduced a small typo in the "go to latest version" tooltips
where a space was missing after the crate name.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-backend Area: Webserver backend S-waiting-on-review Status: This pull request has been implemented and needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show different message than 'Go to latest version' on pre-releases
2 participants