[JENKINS-75602] Report URL in update center failure messages#23920
[JENKINS-75602] Report URL in update center failure messages#23920adhamahmad wants to merge 7 commits intojenkinsci:masterfrom
Conversation
55c28a3 to
6738b17
Compare
…er method in PluginManager class
6738b17 to
f4867b9
Compare
|
I don't understand how this change resolves the reported issue: The stack trace in that message (from Jenkins 2.492.3) is (with some sections removed for brevity): Line 2168 in 2.492.3 PluginManager.java is before your change. It looks like this: Since SocketException is an exception, the new code that you added will not be called because the exception will be thrown before your new code is reached. The stack trace indicates that the exception appeared during a daily check for updates. If that's the case, then I think that the best place to insert the additional error message is in the last call in the Jenkins code base before it enters Java libraries. That would be: core/src/main/java/hudson/model/DownloadService.java where the diff would look like this: That corresponds to the stack trace in the bug report and preserves the original IOException. |
MarkEWaite
left a comment
There was a problem hiding this comment.
As far as I can tell from reading the stack trace in the original report, the changes in the PluginManager class won't resolve the issue that was reported.
Includes the basename of the original exception and the message of the original exception so that the exception message retains the information from the original exception. Without the original exception message and exception class, it can be difficult to understand the cause of the message. Was it a connection timeout or a connection reset or a hostname not found or something else?
|
@adhamahmad could you review the changes that I proposed in 8e91388? I was interested enough in your pull request that I spent some time exploring it and did not want to lose the results of that exploration. |
|
@adhamahmad I won't have more time to spend on this for at least a week. I think that we need some way to retain the desirable user experience of the current code while still providing more details when a failure is logged. If you want to explore it further, that would be great with me. |
|
@MarkEWaite Thanks for taking the time to explore this. I’m reviewing the changes now, including the impact on the user-facing messages versus logging, and will follow up with feedback or updates shortly. |
|
It's also usually helpful to avoid throwing exceptions inside of a catch block. In this case that should also help with adding the URL to the message twice. Untested patchIndex: core/src/main/java/hudson/model/DownloadService.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/core/src/main/java/hudson/model/DownloadService.java b/core/src/main/java/hudson/model/DownloadService.java
--- a/core/src/main/java/hudson/model/DownloadService.java (revision 648ad341564a6df64e97b6d2c99ddaf4c905ad52)
+++ b/core/src/main/java/hudson/model/DownloadService.java (date 1765837735782)
@@ -44,6 +44,7 @@
import java.io.InputStream;
import java.lang.reflect.Field;
import java.net.HttpURLConnection;
+import java.net.SocketException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
@@ -114,12 +115,7 @@
*/
@Restricted(NoExternalUse.class)
public static String loadJSON(URL src) throws IOException {
- URLConnection con = ProxyConfiguration.open(src);
- if (con instanceof HttpURLConnection) {
- // prevent problems from misbehaving plugins disabling redirects by default
- ((HttpURLConnection) con).setInstanceFollowRedirects(true);
- }
- try (InputStream is = con.getInputStream()) {
+ try (InputStream is = openConnection(src)) {
String jsonp = IOUtils.toString(is, StandardCharsets.UTF_8);
int start = jsonp.indexOf('{');
int end = jsonp.lastIndexOf('}');
@@ -131,6 +127,19 @@
}
}
+ private static InputStream openConnection(URL src) throws IOException {
+ URLConnection con = ProxyConfiguration.open(src);
+ if (con instanceof HttpURLConnection) {
+ // prevent problems from misbehaving plugins disabling redirects by default
+ ((HttpURLConnection) con).setInstanceFollowRedirects(true);
+ }
+ try {
+ return con.getInputStream();
+ } catch (SocketException ex) {
+ throw new IOException("Cannot fetch data from " + src + " due to " + ex, ex);
+ }
+ }
+
/**
* Loads JSON from a JSON-with-{@code postMessage} URL.
* @param src a URL to a JSON HTML file (typically including {@code id} and {@code version} query parameters)
@@ -139,12 +148,7 @@
*/
@Restricted(NoExternalUse.class)
public static String loadJSONHTML(URL src) throws IOException {
- URLConnection con = ProxyConfiguration.open(src);
- if (con instanceof HttpURLConnection) {
- // prevent problems from misbehaving plugins disabling redirects by default
- ((HttpURLConnection) con).setInstanceFollowRedirects(true);
- }
- try (InputStream is = con.getInputStream()) {
+ try (InputStream is = openConnection(src)) {
String jsonp = IOUtils.toString(is, StandardCharsets.UTF_8);
String preamble = "window.parent.postMessage(JSON.stringify(";
int start = jsonp.indexOf(preamble); |
|
Hey @MarkEWaite @zbynek, Asking for guidance: can we include the URL in logging only while rethrowing the original exception to maintain the current UI behavior (similar to my previous commit 96cc0e5) ? For reference, here’s the UI error message in case of bad hostname after implementing the suggested |
|
@MarkEWaite |







Fixes #16723
Testing done
Tested the change manually by executing the affected functionality locally.
Attached a screenshot showing the expected behavior after applying the change.
Proposed changelog entries
Proposed changelog category
/label bug
Proposed upgrade guidelines
N/A
Submitter checklist
@Restrictedor have@since TODOJavadocs, as appropriate.@Deprecated(since = "TODO")or@Deprecated(forRemoval = true, since = "TODO"), if applicable.evalto ease future introduction of Content Security Policy (CSP) directives (see documentation).Desired reviewers
@mention
Before the changes are marked as
ready-for-merge:Maintainer checklist
upgrade-guide-neededlabel is set and there is a Proposed upgrade guidelines section in the pull request title (see example).lts-candidateto be considered.