From a168fc472af52fcf4f3f4f3dbdccb1cf807a4c56 Mon Sep 17 00:00:00 2001 From: kohsuke Date: Tue, 30 Mar 2010 22:41:24 +0000 Subject: [PATCH] - Improved the error reporting mechanism in LDAP setting. - improved FormValidation.error(...) so that one can easily send the full stack trace. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@29612 71c3de6d-444a-0410-be80-ed276b4c234a --- .../hudson/security/LDAPSecurityRealm.java | 4 +- .../hudson/tools/ZipExtractionInstaller.java | 2 +- .../main/java/hudson/util/FormValidation.java | 37 +++++++++++++++++++ war/resources/scripts/hudson-behavior.js | 12 +++++- 4 files changed, 51 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/hudson/security/LDAPSecurityRealm.java b/core/src/main/java/hudson/security/LDAPSecurityRealm.java index ab16a303f3..d38bfeef80 100644 --- a/core/src/main/java/hudson/security/LDAPSecurityRealm.java +++ b/core/src/main/java/hudson/security/LDAPSecurityRealm.java @@ -519,12 +519,12 @@ public class LDAPSecurityRealm extends SecurityRealm { } catch (UnknownHostException x) { return FormValidation.error(Messages.LDAPSecurityRealm_UnknownHost(x.getMessage())); } catch (IOException x) { - return FormValidation.error(Messages.LDAPSecurityRealm_UnableToConnect(server, x.getMessage())); + return FormValidation.error(x,Messages.LDAPSecurityRealm_UnableToConnect(server, x.getMessage())); } // otherwise we don't know what caused it, so fall back to the general error report // getMessage() alone doesn't offer enough - return FormValidation.error(Messages.LDAPSecurityRealm_UnableToConnect(server, e)); + return FormValidation.error(e,Messages.LDAPSecurityRealm_UnableToConnect(server, e)); } catch (NumberFormatException x) { // The getLdapCtxInstance method throws this if it fails to parse the port number return FormValidation.error(Messages.LDAPSecurityRealm_InvalidPortNumber()); diff --git a/core/src/main/java/hudson/tools/ZipExtractionInstaller.java b/core/src/main/java/hudson/tools/ZipExtractionInstaller.java index 1213773b8c..69bf037aa3 100644 --- a/core/src/main/java/hudson/tools/ZipExtractionInstaller.java +++ b/core/src/main/java/hudson/tools/ZipExtractionInstaller.java @@ -109,7 +109,7 @@ public class ZipExtractionInstaller extends ToolInstaller { } catch (MalformedURLException x) { return FormValidation.error(Messages.ZipExtractionInstaller_malformed_url()); } catch (IOException x) { - return FormValidation.error(Messages.ZipExtractionInstaller_could_not_connect()); + return FormValidation.error(x,Messages.ZipExtractionInstaller_could_not_connect()); } } diff --git a/core/src/main/java/hudson/util/FormValidation.java b/core/src/main/java/hudson/util/FormValidation.java index a54154590a..a4682afb6a 100644 --- a/core/src/main/java/hudson/util/FormValidation.java +++ b/core/src/main/java/hudson/util/FormValidation.java @@ -24,6 +24,7 @@ package hudson.util; import hudson.EnvVars; +import hudson.Functions; import hudson.Launcher; import hudson.ProxyConfiguration; import hudson.Util; @@ -161,6 +162,42 @@ public abstract class FormValidation extends IOException implements HttpResponse return ok(String.format(format,args)); } + /** + * Sends out a string error message, with optional "show details" link that expands to the full stack trace. + * + *

+ * Use this with caution, so that anonymous users do not gain too much insights into the state of the system, + * as error stack trace often reveals a lot of information. Consider if a check operation needs to be exposed + * to everyone or just those who have higher access to job/hudson/etc. + */ + public static FormValidation error(Throwable e, String message) { + return _error(Kind.ERROR, e, message); + } + + public static FormValidation warning(Throwable e, String message) { + return _error(Kind.WARNING, e, message); + } + + private static FormValidation _error(Kind kind, Throwable e, String message) { + if (e==null) return _errorWithMarkup(Util.escape(message),kind); + + return _errorWithMarkup(Util.escape(message)+ + " (show details)

"
+                  + Functions.printThrowable(e) +
+            "
",kind + ); + } + + public static FormValidation error(Throwable e, String format, Object... args) { + return error(e,String.format(format,args)); + } + + public static FormValidation warning(Throwable e, String format, Object... args) { + return warning(e,String.format(format,args)); + } + + + /** * Sends out an HTML fragment that indicates an error. * diff --git a/war/resources/scripts/hudson-behavior.js b/war/resources/scripts/hudson-behavior.js index 5b94adc350..660cf58592 100644 --- a/war/resources/scripts/hudson-behavior.js +++ b/war/resources/scripts/hudson-behavior.js @@ -122,6 +122,7 @@ var FormChecker = { method : next.method, onComplete : function(x) { next.target.innerHTML = x.responseText; + Behaviour.applySubtree(next.target); FormChecker.inProgress--; FormChecker.schedule(); } @@ -307,6 +308,7 @@ function registerValidator(e) { method : method, onComplete : function(x) { target.innerHTML = x.responseText; + Behaviour.applySubtree(target); } }); } @@ -852,8 +854,16 @@ var hudsonRules = { }); refill(); // initial fill - } + }, + "A.showDetails" : function(e) { + e.onclick = function() { + this.style.display = 'none'; + this.nextSibling.style.display = 'block'; + return false; + }; + e = null; // avoid memory leak + } }; function applyTooltip(e,text) {