提交 a168fc47 编写于 作者: K kohsuke

- 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
上级 67cc6af1
......@@ -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());
......
......@@ -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());
}
}
......
......@@ -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.
*
* <p>
* 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)+
" <a href='#' class='showDetails'>(show details)</a><pre style='display:none'>"
+ Functions.printThrowable(e) +
"</pre>",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.
*
......
......@@ -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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册