Skip to content

Commit f75f403

Browse files
committed
Auto merge of #5061 - ehuss:git-error-auth, r=alexcrichton
Display git errors during authentication. Certain git errors during authentication were being converted to internal errors which meant that they are only seen if you pass `--verbose`. This may not be obvious, and many of these messages are helpful for diagnosing git errors. This change makes these errors always be displayed. Fixes #5035. Note: Some of the git errors are currently unhelpful. Once Cargo has updated git2-rs to include alexcrichton/git2-rs#298, these errors will improve. (@alexcrichton, I can make a PR to update Cargo for the changes in git2 if you'd like). I'm uncertain if this is a good solution, since the error messages in some cases are a little verbose (such as showing `class=...`). Here is a sample of what some of the messages look like: <details><summary>Error Message Examples</summary> <p> Example of the git message shown below the "attempted yadda yadda" message. Scenario | Message ---------|-------- No ssh-agent, multiple usernames | `error authenticating: ; class=Ssh (23)` | | †`error authenticating: no auth sock variable; class=Ssh (23)` No ssh-agent, one username | `an unknown git error occurred` | | †`error authenticating: no auth sock variable; class=Ssh (23)` Incorrect ssh-agent setup | `error authenticating: failed connecting with agent; class=Ssh (23)` ssh-agent no keys, one username | `an unknown git error occurred` | | †`failed to acquire username/password from local configuration` ssh-agent no keys, multiple usernames | `error authenticating: ; class=Ssh (23)` | | †`no authentication available` auth success, bad path | `fatal: '/path/to/repo/' does not appear to be a git repository; class=Ssh (23); code=Eof (-20)` | | ‡`ERROR: Repository not found.; class=Ssh (23); code=Eof (-20)` bad username | `an unknown git error occurred` | | †`failed to acquire username/password from local configuration` | | ‡`error authenticating: Username/PublicKey combination invalid; class=Ssh (23)` † - Messages once git2-rs is updated. ‡ - Github message </p> </details>
2 parents 6468ba2 + f66fe2c commit f75f403

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/cargo/sources/git/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use url::Url;
1212

1313
use core::GitReference;
1414
use util::{ToUrl, internal, Config, network, Progress};
15-
use util::errors::{CargoResult, CargoResultExt, Internal};
15+
use util::errors::{CargoResult, CargoResultExt, CargoError};
1616

1717
#[derive(PartialEq, Clone, Debug)]
1818
pub struct GitRevision(git2::Oid);
@@ -546,7 +546,7 @@ fn with_authentication<T, F>(url: &str, cfg: &git2::Config, mut f: F)
546546
// In the case of an authentication failure (where we tried something) then
547547
// we try to give a more helpful error message about precisely what we
548548
// tried.
549-
let res = res.map_err(Internal::new).chain_err(|| {
549+
let res = res.map_err(CargoError::from).chain_err(|| {
550550
let mut msg = "failed to authenticate when downloading \
551551
repository".to_string();
552552
if !ssh_agent_attempts.is_empty() {

tests/testsuite/build_auth.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ fn http_auth_offered() {
103103
")
104104
.build();
105105

106+
// This is a "contains" check because the last error differs by platform,
107+
// may span multiple lines, and isn't relevant to this test.
106108
assert_that(p.cargo("build"),
107-
execs().with_status(101).with_stderr(&format!("\
109+
execs().with_status(101).with_stderr_contains(&format!("\
108110
[UPDATING] git repository `http://{addr}/foo/bar`
109111
[ERROR] failed to load source for a dependency on `bar`
110112
@@ -118,7 +120,7 @@ Caused by:
118120
failed to authenticate when downloading repository
119121
attempted to find username/password via `credential.helper`, but [..]
120122
121-
To learn more, run the command again with --verbose.
123+
Caused by:
122124
",
123125
addr = addr)));
124126

0 commit comments

Comments
 (0)