Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow plugins to override boot failure view #8442

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion core/src/main/java/hudson/WebAppMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.Charset;
Expand Down Expand Up @@ -261,13 +262,36 @@ public void run() {
new HudsonFailedToLoad(e).publish(context, _home);
throw e;
} catch (Exception e) {
new HudsonFailedToLoad(e).publish(context, _home);
// Allow plugins to override error page on boot with custom BootFailure subclass thrown
Throwable error = unwrapException(e);
if (error instanceof InvocationTargetException) {
Throwable targetException = ((InvocationTargetException) error).getTargetException();

if (targetException instanceof BootFailure) {
((BootFailure) targetException).publish(context, _home);
} else {
new HudsonFailedToLoad(e).publish(context, _home);
}
} else {
new HudsonFailedToLoad(e).publish(context, _home);
}
} finally {
Jenkins instance = Jenkins.getInstanceOrNull();
if (!success && instance != null)
instance.cleanUp();
}
}

private Throwable unwrapException(Exception e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be simplified to return @CheckForNull BootFailure.

Throwable error = e;
while (error.getCause() != null) {
if (error.getCause() instanceof InvocationTargetException) {
return error.getCause();
}
error = error.getCause();
}
return error;
}
};
initThread.start();
} catch (BootFailure e) {
Expand Down