Skip to content
Permalink
Browse files

[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.
  • Loading branch information
kohsuke committed Nov 30, 2011
1 parent 887d6cf commit 9bcf9b0bfba9089a62a701c1137b44493bc9a4ec
Showing with 29 additions and 25 deletions.
  1. +29 −25 core/src/main/java/hudson/model/UpdateCenter.java
@@ -622,37 +622,41 @@ public void postValidate(DownloadJob job, File src) throws IOException {
* @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);
}
}

/**

0 comments on commit 9bcf9b0

Please sign in to comment.