Skip to content

Commit

Permalink
More informative error on upload errors
Browse files Browse the repository at this point in the history
  • Loading branch information
konstin committed Jul 19, 2019
1 parent 3864c41 commit 71f4705
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 65 deletions.
18 changes: 14 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
authors = ["konstin <konstin@mailbox.org>"]
name = "pyo3-pack"
version = "0.7.0-beta.8"
version = "0.7.0-beta.9"
description = "Build and publish crates with pyo3, rust-cpython and cffi bindings as well as rust binaries as python packages"
exclude = ["test-crates/**/*", "sysconfig/*", "test-data/*", "ci/*", "tests/*"]
readme = "Readme.md"
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ install:
- ps: if ($env:channel -like "nightly-2019-05-04") { .\ci\setup.ps1 }

# From and for ring
- IF "%CHANNEL%" == "nightly-2019-05-04" (call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64)
- IF "%CHANNEL%" == "nightly-2019-05-04" (call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64)

- echo %PATH%
- echo %LIBPATH%
Expand Down
119 changes: 60 additions & 59 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,69 +320,70 @@ fn upload_ui(build: BuildOptions, publish: &PublishOpt, no_sdist: bool) -> Resul
loop {
println!("🚀 Uploading {} packages", wheels.len());

// Upload all wheels, aborting on the first error
let result = wheels
.iter()
.map(|(wheel_path, supported_versions, _)| {
upload(
&registry,
&wheel_path,
&build_context.metadata21,
&supported_versions,
)
})
.collect();

match result {
Ok(()) => {
println!("✨ Packages uploaded succesfully");

#[cfg(feature = "keyring")]
{
// We know the password is correct, so we can save it in the keyring
let username = registry.username.clone();
let keyring = Keyring::new(&env!("CARGO_PKG_NAME"), &username);
let password = registry.password.clone();
keyring.set_password(&password).unwrap_or_else(|e| {
eprintln!("⚠ Failed to store the password in the keyring: {:?}", e)
});
}

return Ok(());
}
Err(UploadError::AuthenticationError) if reenter => {
println!("⛔ Username and/or password are wrong");

#[cfg(feature = "keyring")]
{
// Delete the wrong password from the keyring
let old_username = registry.username.clone();
let keyring = Keyring::new(&env!("CARGO_PKG_NAME"), &old_username);
match keyring.delete_password() {
Ok(()) => {}
Err(KeyringError::NoPasswordFound) | Err(KeyringError::NoBackendFound) => {}
_ => eprintln!("⚠ Failed to remove password from keyring"),
for (wheel_path, supported_versions, _) in &wheels {
let result = upload(
&registry,
&wheel_path,
&build_context.metadata21,
&supported_versions,
);
match result {
Ok(()) => {
println!("✨ Packages uploaded succesfully");

#[cfg(feature = "keyring")]
{
// We know the password is correct, so we can save it in the keyring
let username = registry.username.clone();
let keyring = Keyring::new(&env!("CARGO_PKG_NAME"), &username);
let password = registry.password.clone();
keyring.set_password(&password).unwrap_or_else(|e| {
eprintln!("⚠ Failed to store the password in the keyring: {:?}", e)
});
}

return Ok(());
}
Err(UploadError::AuthenticationError) if reenter => {
println!("⛔ Username and/or password are wrong");

#[cfg(feature = "keyring")]
{
// Delete the wrong password from the keyring
let old_username = registry.username.clone();
let keyring = Keyring::new(&env!("CARGO_PKG_NAME"), &old_username);
match keyring.delete_password() {
Ok(()) => {}
Err(KeyringError::NoPasswordFound)
| Err(KeyringError::NoBackendFound) => {}
_ => eprintln!("⚠ Failed to remove password from keyring"),
}
}

let username = get_username();
let password = rpassword::prompt_password_stdout("Please enter your password: ")
.unwrap_or_else(|_| {
// So we need this fallback for pycharm on windows
let mut password = String::new();
io::stdin()
.read_line(&mut password)
.expect("Failed to read line");
password.trim().to_string()
});

registry = Registry::new(username, password, registry.url);
println!("… Retrying")
}
Err(UploadError::AuthenticationError) => {
bail!("Username and/or password are wrong");
let username = get_username();
let password =
rpassword::prompt_password_stdout("Please enter your password: ")
.unwrap_or_else(|_| {
// So we need this fallback for pycharm on windows
let mut password = String::new();
io::stdin()
.read_line(&mut password)
.expect("Failed to read line");
password.trim().to_string()
});

registry = Registry::new(username, password, registry.url);
println!("… Retrying");
break;
}
Err(UploadError::AuthenticationError) => {
bail!("Username and/or password are wrong");
}
Err(err) => {
let filename = wheel_path.file_name().unwrap_or(&wheel_path.as_os_str());
return Err(err).context(format!("💥 Failed to upload {:?}", filename))?;
}
}
Err(err) => return Err(err).context("💥 Failed to upload")?,
}
}
}
Expand Down

0 comments on commit 71f4705

Please sign in to comment.