{"action":"created","comment":{"url":"https://api.github.com/repos/rust-lang/cargo/pulls/comments/62889476","id":62889476,"diff_hunk":"@@ -0,0 +1,86 @@\n+use util::{CargoResult, Config, errors};\n+\n+/// Wrapper method for network call retry logic.\n+///\n+/// Retry counts provided by Config object 'net.retry'. Config shell outputs\n+/// a warning on per retry.\n+///\n+/// Closure must return a CargoResult.\n+///\n+/// Example:\n+/// use util::network;\n+/// cargo_result = network.with_retry(&config, || something.download());\n+pub fn with_retry<T, E, F>(config: &Config, mut callback: F) -> CargoResult<T>\n+    where F: FnMut() -> Result<T, E>,\n+          E: errors::NetworkError\n+{\n+    let mut remaining = try!(config.net_retry());\n+    loop {\n+        match callback() {\n+            Ok(ret) => return Ok(ret),\n+            Err(ref e) if e.maybe_spurious() && remaining > 0 => {\n+                try!(config.shell()\n+                           .warn(format!(\"failed network call {} \\\n+                                        tries remaining\", remaining)));","path":"src/cargo/util/network.rs","position":24,"original_position":24,"commit_id":"827d3b6b0c719c53c50ab38d9e9f3bd0060d7082","original_commit_id":"827d3b6b0c719c53c50ab38d9e9f3bd0060d7082","user":{"login":"alexcrichton","id":64996,"avatar_url":"https://avatars.githubusercontent.com/u/64996?v=3","gravatar_id":"","url":"https://api.github.com/users/alexcrichton","html_url":"https://github.com/alexcrichton","followers_url":"https://api.github.com/users/alexcrichton/followers","following_url":"https://api.github.com/users/alexcrichton/following{/other_user}","gists_url":"https://api.github.com/users/alexcrichton/gists{/gist_id}","starred_url":"https://api.github.com/users/alexcrichton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexcrichton/subscriptions","organizations_url":"https://api.github.com/users/alexcrichton/orgs","repos_url":"https://api.github.com/users/alexcrichton/repos","events_url":"https://api.github.com/users/alexcrichton/events{/privacy}","received_events_url":"https://api.github.com/users/alexcrichton/received_events","type":"User","site_admin":false},"body":"Perhaps this could also print out the error (just for reference)","created_at":"2016-05-11T17:23:25Z","updated_at":"2016-05-11T17:23:25Z","html_url":"https://github.com/rust-lang/cargo/pull/2396#discussion_r62889476","pull_request_url":"https://api.github.com/repos/rust-lang/cargo/pulls/2396","_links":{"self":{"href":"https://api.github.com/repos/rust-lang/cargo/pulls/comments/62889476"},"html":{"href":"https://github.com/rust-lang/cargo/pull/2396#discussion_r62889476"},"pull_request":{"href":"https://api.github.com/repos/rust-lang/cargo/pulls/2396"}}},"pull_request":{"url":"https://api.github.com/repos/rust-lang/cargo/pulls/2396","id":59907037,"html_url":"https://github.com/rust-lang/cargo/pull/2396","diff_url":"https://github.com/rust-lang/cargo/pull/2396.diff","patch_url":"https://github.com/rust-lang/cargo/pull/2396.patch","issue_url":"https://api.github.com/repos/rust-lang/cargo/issues/2396","number":2396,"state":"open","locked":false,"title":"Network retry issue 1602","user":{"login":"sbeckeriv","id":12170,"avatar_url":"https://avatars.githubusercontent.com/u/12170?v=3","gravatar_id":"","url":"https://api.github.com/users/sbeckeriv","html_url":"https://github.com/sbeckeriv","followers_url":"https://api.github.com/users/sbeckeriv/followers","following_url":"https://api.github.com/users/sbeckeriv/following{/other_user}","gists_url":"https://api.github.com/users/sbeckeriv/gists{/gist_id}","starred_url":"https://api.github.com/users/sbeckeriv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sbeckeriv/subscriptions","organizations_url":"https://api.github.com/users/sbeckeriv/orgs","repos_url":"https://api.github.com/users/sbeckeriv/repos","events_url":"https://api.github.com/users/sbeckeriv/events{/privacy}","received_events_url":"https://api.github.com/users/sbeckeriv/received_events","type":"User","site_admin":false},"body":"This resolves #1602 \r\n\r\nAdd in a net.retry value in the config. \r\n\r\nThe default value is 2 which is set per check of the config. I was unsure the best way to do that. I had a thought to put it in util::config like a few other named configs but wondered its usefulness. I do blindly retry all errors still, however, I use shell().say to print the debug of the error. \t\r\n\r\nI am looking for the other network calls. I need to check over the src/cargo/sources for more locations, but I had questions with regards to test. How do I setup a test value in the toml config? I would also like to set the default retry to 0 for test. I updated 4 test tomls to include net.retry=0, however, my .cargo/config is still affecting tests.\r\n\r\n Also I am unsure where the documentation for new config goes. \r\n\r\nThanks\r\nBecker","created_at":"2016-02-19T05:40:20Z","updated_at":"2016-05-11T17:23:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1392a9ac4281e66a1cb3c366ba8b06ff3e547853","assignee":{"login":"alexcrichton","id":64996,"avatar_url":"https://avatars.githubusercontent.com/u/64996?v=3","gravatar_id":"","url":"https://api.github.com/users/alexcrichton","html_url":"https://github.com/alexcrichton","followers_url":"https://api.github.com/users/alexcrichton/followers","following_url":"https://api.github.com/users/alexcrichton/following{/other_user}","gists_url":"https://api.github.com/users/alexcrichton/gists{/gist_id}","starred_url":"https://api.github.com/users/alexcrichton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexcrichton/subscriptions","organizations_url":"https://api.github.com/users/alexcrichton/orgs","repos_url":"https://api.github.com/users/alexcrichton/repos","events_url":"https://api.github.com/users/alexcrichton/events{/privacy}","received_events_url":"https://api.github.com/users/alexcrichton/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/rust-lang/cargo/pulls/2396/commits","review_comments_url":"https://api.github.com/repos/rust-lang/cargo/pulls/2396/comments","review_comment_url":"https://api.github.com/repos/rust-lang/cargo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rust-lang/cargo/issues/2396/comments","statuses_url":"https://api.github.com/repos/rust-lang/cargo/statuses/827d3b6b0c719c53c50ab38d9e9f3bd0060d7082","head":{"label":"sbeckeriv:network-retry-1602","ref":"network-retry-1602","sha":"827d3b6b0c719c53c50ab38d9e9f3bd0060d7082","user":{"login":"sbeckeriv","id":12170,"avatar_url":"https://avatars.githubusercontent.com/u/12170?v=3","gravatar_id":"","url":"https://api.github.com/users/sbeckeriv","html_url":"https://github.com/sbeckeriv","followers_url":"https://api.github.com/users/sbeckeriv/followers","following_url":"https://api.github.com/users/sbeckeriv/following{/other_user}","gists_url":"https://api.github.com/users/sbeckeriv/gists{/gist_id}","starred_url":"https://api.github.com/users/sbeckeriv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sbeckeriv/subscriptions","organizations_url":"https://api.github.com/users/sbeckeriv/orgs","repos_url":"https://api.github.com/users/sbeckeriv/repos","events_url":"https://api.github.com/users/sbeckeriv/events{/privacy}","received_events_url":"https://api.github.com/users/sbeckeriv/received_events","type":"User","site_admin":false},"repo":{"id":35737461,"name":"cargo","full_name":"sbeckeriv/cargo","owner":{"login":"sbeckeriv","id":12170,"avatar_url":"https://avatars.githubusercontent.com/u/12170?v=3","gravatar_id":"","url":"https://api.github.com/users/sbeckeriv","html_url":"https://github.com/sbeckeriv","followers_url":"https://api.github.com/users/sbeckeriv/followers","following_url":"https://api.github.com/users/sbeckeriv/following{/other_user}","gists_url":"https://api.github.com/users/sbeckeriv/gists{/gist_id}","starred_url":"https://api.github.com/users/sbeckeriv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sbeckeriv/subscriptions","organizations_url":"https://api.github.com/users/sbeckeriv/orgs","repos_url":"https://api.github.com/users/sbeckeriv/repos","events_url":"https://api.github.com/users/sbeckeriv/events{/privacy}","received_events_url":"https://api.github.com/users/sbeckeriv/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sbeckeriv/cargo","description":"The Rust package manager","fork":true,"url":"https://api.github.com/repos/sbeckeriv/cargo","forks_url":"https://api.github.com/repos/sbeckeriv/cargo/forks","keys_url":"https://api.github.com/repos/sbeckeriv/cargo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sbeckeriv/cargo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sbeckeriv/cargo/teams","hooks_url":"https://api.github.com/repos/sbeckeriv/cargo/hooks","issue_events_url":"https://api.github.com/repos/sbeckeriv/cargo/issues/events{/number}","events_url":"https://api.github.com/repos/sbeckeriv/cargo/events","assignees_url":"https://api.github.com/repos/sbeckeriv/cargo/assignees{/user}","branches_url":"https://api.github.com/repos/sbeckeriv/cargo/branches{/branch}","tags_url":"https://api.github.com/repos/sbeckeriv/cargo/tags","blobs_url":"https://api.github.com/repos/sbeckeriv/cargo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sbeckeriv/cargo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sbeckeriv/cargo/git/refs{/sha}","trees_url":"https://api.github.com/repos/sbeckeriv/cargo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sbeckeriv/cargo/statuses/{sha}","languages_url":"https://api.github.com/repos/sbeckeriv/cargo/languages","stargazers_url":"https://api.github.com/repos/sbeckeriv/cargo/stargazers","contributors_url":"https://api.github.com/repos/sbeckeriv/cargo/contributors","subscribers_url":"https://api.github.com/repos/sbeckeriv/cargo/subscribers","subscription_url":"https://api.github.com/repos/sbeckeriv/cargo/subscription","commits_url":"https://api.github.com/repos/sbeckeriv/cargo/commits{/sha}","git_commits_url":"https://api.github.com/repos/sbeckeriv/cargo/git/commits{/sha}","comments_url":"https://api.github.com/repos/sbeckeriv/cargo/comments{/number}","issue_comment_url":"https://api.github.com/repos/sbeckeriv/cargo/issues/comments{/number}","contents_url":"https://api.github.com/repos/sbeckeriv/cargo/contents/{+path}","compare_url":"https://api.github.com/repos/sbeckeriv/cargo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sbeckeriv/cargo/merges","archive_url":"https://api.github.com/repos/sbeckeriv/cargo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sbeckeriv/cargo/downloads","issues_url":"https://api.github.com/repos/sbeckeriv/cargo/issues{/number}","pulls_url":"https://api.github.com/repos/sbeckeriv/cargo/pulls{/number}","milestones_url":"https://api.github.com/repos/sbeckeriv/cargo/milestones{/number}","notifications_url":"https://api.github.com/repos/sbeckeriv/cargo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sbeckeriv/cargo/labels{/name}","releases_url":"https://api.github.com/repos/sbeckeriv/cargo/releases{/id}","deployments_url":"https://api.github.com/repos/sbeckeriv/cargo/deployments","created_at":"2015-05-16T19:37:13Z","updated_at":"2016-02-15T23:24:37Z","pushed_at":"2016-05-11T05:34:16Z","git_url":"git://github.com/sbeckeriv/cargo.git","ssh_url":"git@github.com:sbeckeriv/cargo.git","clone_url":"https://github.com/sbeckeriv/cargo.git","svn_url":"https://github.com/sbeckeriv/cargo","homepage":"http://crates.io/","size":9178,"stargazers_count":0,"watchers_count":0,"language":"Rust","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rust-lang:master","ref":"master","sha":"d6e1726b5dc0e3bdf502df80579c85e2feed866d","user":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars.githubusercontent.com/u/5430905?v=3","gravatar_id":"","url":"https://api.github.com/users/rust-lang","html_url":"https://github.com/rust-lang","followers_url":"https://api.github.com/users/rust-lang/followers","following_url":"https://api.github.com/users/rust-lang/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang/subscriptions","organizations_url":"https://api.github.com/users/rust-lang/orgs","repos_url":"https://api.github.com/users/rust-lang/repos","events_url":"https://api.github.com/users/rust-lang/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang/received_events","type":"Organization","site_admin":false},"repo":{"id":17420913,"name":"cargo","full_name":"rust-lang/cargo","owner":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars.githubusercontent.com/u/5430905?v=3","gravatar_id":"","url":"https://api.github.com/users/rust-lang","html_url":"https://github.com/rust-lang","followers_url":"https://api.github.com/users/rust-lang/followers","following_url":"https://api.github.com/users/rust-lang/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang/subscriptions","organizations_url":"https://api.github.com/users/rust-lang/orgs","repos_url":"https://api.github.com/users/rust-lang/repos","events_url":"https://api.github.com/users/rust-lang/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rust-lang/cargo","description":"The Rust package manager","fork":false,"url":"https://api.github.com/repos/rust-lang/cargo","forks_url":"https://api.github.com/repos/rust-lang/cargo/forks","keys_url":"https://api.github.com/repos/rust-lang/cargo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rust-lang/cargo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rust-lang/cargo/teams","hooks_url":"https://api.github.com/repos/rust-lang/cargo/hooks","issue_events_url":"https://api.github.com/repos/rust-lang/cargo/issues/events{/number}","events_url":"https://api.github.com/repos/rust-lang/cargo/events","assignees_url":"https://api.github.com/repos/rust-lang/cargo/assignees{/user}","branches_url":"https://api.github.com/repos/rust-lang/cargo/branches{/branch}","tags_url":"https://api.github.com/repos/rust-lang/cargo/tags","blobs_url":"https://api.github.com/repos/rust-lang/cargo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rust-lang/cargo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rust-lang/cargo/git/refs{/sha}","trees_url":"https://api.github.com/repos/rust-lang/cargo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rust-lang/cargo/statuses/{sha}","languages_url":"https://api.github.com/repos/rust-lang/cargo/languages","stargazers_url":"https://api.github.com/repos/rust-lang/cargo/stargazers","contributors_url":"https://api.github.com/repos/rust-lang/cargo/contributors","subscribers_url":"https://api.github.com/repos/rust-lang/cargo/subscribers","subscription_url":"https://api.github.com/repos/rust-lang/cargo/subscription","commits_url":"https://api.github.com/repos/rust-lang/cargo/commits{/sha}","git_commits_url":"https://api.github.com/repos/rust-lang/cargo/git/commits{/sha}","comments_url":"https://api.github.com/repos/rust-lang/cargo/comments{/number}","issue_comment_url":"https://api.github.com/repos/rust-lang/cargo/issues/comments{/number}","contents_url":"https://api.github.com/repos/rust-lang/cargo/contents/{+path}","compare_url":"https://api.github.com/repos/rust-lang/cargo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rust-lang/cargo/merges","archive_url":"https://api.github.com/repos/rust-lang/cargo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rust-lang/cargo/downloads","issues_url":"https://api.github.com/repos/rust-lang/cargo/issues{/number}","pulls_url":"https://api.github.com/repos/rust-lang/cargo/pulls{/number}","milestones_url":"https://api.github.com/repos/rust-lang/cargo/milestones{/number}","notifications_url":"https://api.github.com/repos/rust-lang/cargo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rust-lang/cargo/labels{/name}","releases_url":"https://api.github.com/repos/rust-lang/cargo/releases{/id}","deployments_url":"https://api.github.com/repos/rust-lang/cargo/deployments","created_at":"2014-03-04T23:20:42Z","updated_at":"2016-05-11T17:20:54Z","pushed_at":"2016-05-11T16:09:12Z","git_url":"git://github.com/rust-lang/cargo.git","ssh_url":"git@github.com:rust-lang/cargo.git","clone_url":"https://github.com/rust-lang/cargo.git","svn_url":"https://github.com/rust-lang/cargo","homepage":"http://crates.io/","size":58381,"stargazers_count":1622,"watchers_count":1622,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":375,"mirror_url":null,"open_issues_count":291,"forks":375,"open_issues":291,"watchers":1622,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rust-lang/cargo/pulls/2396"},"html":{"href":"https://github.com/rust-lang/cargo/pull/2396"},"issue":{"href":"https://api.github.com/repos/rust-lang/cargo/issues/2396"},"comments":{"href":"https://api.github.com/repos/rust-lang/cargo/issues/2396/comments"},"review_comments":{"href":"https://api.github.com/repos/rust-lang/cargo/pulls/2396/comments"},"review_comment":{"href":"https://api.github.com/repos/rust-lang/cargo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rust-lang/cargo/pulls/2396/commits"},"statuses":{"href":"https://api.github.com/repos/rust-lang/cargo/statuses/827d3b6b0c719c53c50ab38d9e9f3bd0060d7082"}}}}