Skip to content

Commit

Permalink
[FIXED JENKINS-11598] improving the error diagnostics.
Browse files Browse the repository at this point in the history
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 9bcf9b0
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions core/src/main/java/hudson/model/UpdateCenter.java
Expand Up @@ -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);
}
}

/**
Expand Down

0 comments on commit 9bcf9b0

Please sign in to comment.