提交 9bcf9b0b 编写于 作者: K Kohsuke Kawaguchi

[FIXED JENKINS-11598] improving the error diagnostics.

Note that the root cause isn't in Jenkins. See "Caused by: java.net.ConnectException: Connection refused: connect" line that indicates a problem in the network connectivity. But this change improves the error diagnostics.
上级 887d6cff
......@@ -622,37 +622,41 @@ public class UpdateCenter extends AbstractModelObject implements Saveable {
* @see DownloadJob
*/
public File download(DownloadJob job, URL src) throws IOException {
URLConnection con = connect(job,src);
int total = con.getContentLength();
CountingInputStream in = new CountingInputStream(con.getInputStream());
byte[] buf = new byte[8192];
int len;
try {
URLConnection con = connect(job,src);
int total = con.getContentLength();
CountingInputStream in = new CountingInputStream(con.getInputStream());
byte[] buf = new byte[8192];
int len;
File dst = job.getDestination();
File tmp = new File(dst.getPath()+".tmp");
OutputStream out = new FileOutputStream(tmp);
File dst = job.getDestination();
File tmp = new File(dst.getPath()+".tmp");
OutputStream out = new FileOutputStream(tmp);
LOGGER.info("Downloading "+job.getName());
try {
while((len=in.read(buf))>=0) {
out.write(buf,0,len);
job.status = job.new Installing(total==-1 ? -1 : in.getCount()*100/total);
LOGGER.info("Downloading "+job.getName());
try {
while((len=in.read(buf))>=0) {
out.write(buf,0,len);
job.status = job.new Installing(total==-1 ? -1 : in.getCount()*100/total);
}
} catch (IOException e) {
throw new IOException2("Failed to load "+src+" to "+tmp,e);
}
} catch (IOException e) {
throw new IOException2("Failed to load "+src+" to "+tmp,e);
}
in.close();
out.close();
in.close();
out.close();
if (total!=-1 && total!=tmp.length()) {
// don't know exactly how this happens, but report like
// http://www.ashlux.com/wordpress/2009/08/14/hudson-and-the-sonar-plugin-fail-maveninstallation-nosuchmethoderror/
// indicates that this kind of inconsistency can happen. So let's be defensive
throw new IOException("Inconsistent file length: expected "+total+" but only got "+tmp.length());
}
if (total!=-1 && total!=tmp.length()) {
// don't know exactly how this happens, but report like
// http://www.ashlux.com/wordpress/2009/08/14/hudson-and-the-sonar-plugin-fail-maveninstallation-nosuchmethoderror/
// indicates that this kind of inconsistency can happen. So let's be defensive
throw new IOException("Inconsistent file length: expected "+total+" but only got "+tmp.length());
}
return tmp;
return tmp;
} catch (IOException e) {
throw new IOException2("Failed to download from "+src,e);
}
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册