Skip to content

Commit 6789d8a

Browse files
committed
Auto merge of #6808 - sgrif:sg-backport-errors-beta, r=alexcrichton
[beta] Backport #6771
2 parents 436f290 + 067c199 commit 6789d8a

File tree

7 files changed

+20
-38
lines changed

7 files changed

+20
-38
lines changed

.travis.yml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,6 @@ matrix:
2323
rust: beta
2424
if: branch != master OR type = pull_request
2525

26-
# Minimum Rust supported channel. We enable these to make sure we
27-
# continue to work on the advertised minimum Rust version.
28-
# However cargo only supports the latest stable so this will get
29-
# increased every 6 weeks or so when the first PR to use a new feature.
30-
- env: TARGET=x86_64-unknown-linux-gnu
31-
ALT=i686-unknown-linux-gnu
32-
rust: 1.31.0
33-
script:
34-
- rustup toolchain install nightly || travis_terminate 1
35-
- cargo +nightly generate-lockfile -Z minimal-versions || travis_terminate 1
36-
- cargo -V || travis_terminate 1
37-
- cargo test --features=deny-warnings || travis_terminate 1
38-
if: branch != master OR type = pull_request
39-
4026
- env: TARGET=x86_64-unknown-linux-gnu
4127
ALT=i686-unknown-linux-gnu
4228
rust: nightly

appveyor.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ environment:
22
matrix:
33
- TARGET: x86_64-pc-windows-msvc
44
OTHER_TARGET: i686-pc-windows-msvc
5-
- TARGET: x86_64-pc-windows-msvc
6-
MINIMAL_VERSIONS: true
7-
CFG_DISABLE_CROSS_TESTS: 1
85

96
install:
107
- if NOT defined APPVEYOR_PULL_REQUEST_NUMBER if "%APPVEYOR_REPO_BRANCH%" == "master" appveyor exit

src/cargo/util/errors.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ pub fn process_error(
307307

308308
#[cfg(unix)]
309309
fn status_to_string(status: ExitStatus) -> String {
310-
use libc;
311310
use std::os::unix::process::*;
312311

313312
if let Some(signal) = status.signal() {

src/cargo/util/paths.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ pub fn path2bytes(path: &Path) -> CargoResult<&[u8]> {
217217

218218
#[cfg(unix)]
219219
pub fn bytes2path(bytes: &[u8]) -> CargoResult<PathBuf> {
220-
use std::ffi::OsStr;
221220
use std::os::unix::prelude::*;
222221
Ok(PathBuf::from(OsStr::from_bytes(bytes)))
223222
}

src/crates-io/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ path = "lib.rs"
1616
[dependencies]
1717
curl = "0.4"
1818
failure = "0.1.1"
19+
http = "0.1"
1920
serde = { version = "1.0", features = ['derive'] }
2021
serde_derive = "1.0"
2122
serde_json = "1.0"

src/crates-io/lib.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::io::Cursor;
88

99
use curl::easy::{Easy, List};
1010
use failure::bail;
11+
use http::status::StatusCode;
1112
use serde::{Deserialize, Serialize};
1213
use serde_json;
1314
use url::percent_encoding::{percent_encode, QUERY_ENCODE_SET};
@@ -323,30 +324,31 @@ fn handle(handle: &mut Easy, read: &mut dyn FnMut(&mut [u8]) -> usize) -> Result
323324
handle.perform()?;
324325
}
325326

326-
match handle.response_code()? {
327-
0 => {} // file upload url sometimes
328-
200 => {}
329-
403 => bail!("received 403 unauthorized response code"),
330-
404 => bail!("received 404 not found response code"),
331-
code => bail!(
327+
let body = match String::from_utf8(body) {
328+
Ok(body) => body,
329+
Err(..) => bail!("response body was not valid utf-8"),
330+
};
331+
let errors = serde_json::from_str::<ApiErrorList>(&body).ok().map(|s| {
332+
s.errors.into_iter().map(|s| s.detail).collect::<Vec<_>>()
333+
});
334+
335+
match (handle.response_code()?, errors) {
336+
(0, None) | (200, None) => {},
337+
(code, Some(errors)) => {
338+
let code = StatusCode::from_u16(code as _)?;
339+
bail!("api errors (status {}): {}", code, errors.join(", "))
340+
}
341+
(code, None) => bail!(
332342
"failed to get a 200 OK response, got {}\n\
333343
headers:\n\
334344
\t{}\n\
335345
body:\n\
336346
{}",
337-
code,
338-
headers.join("\n\t"),
339-
String::from_utf8_lossy(&body)
347+
code,
348+
headers.join("\n\t"),
349+
body,
340350
),
341351
}
342352

343-
let body = match String::from_utf8(body) {
344-
Ok(body) => body,
345-
Err(..) => bail!("response body was not valid utf-8"),
346-
};
347-
if let Ok(errors) = serde_json::from_str::<ApiErrorList>(&body) {
348-
let errors = errors.errors.into_iter().map(|s| s.detail);
349-
bail!("api errors: {}", errors.collect::<Vec<_>>().join(", "));
350-
}
351353
Ok(body)
352354
}

tests/testsuite/death.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ fn ctrl_c_kills_everyone() {
131131

132132
#[cfg(unix)]
133133
fn ctrl_c(child: &mut Child) {
134-
use libc;
135-
136134
let r = unsafe { libc::kill(-(child.id() as i32), libc::SIGINT) };
137135
if r < 0 {
138136
panic!("failed to kill: {}", io::Error::last_os_error());

0 commit comments

Comments
 (0)