Allow plugins to override boot failure view (#8442)

This commit is contained in:
Tim Jacomb authored and GitHub committed 2024-01-05 20:40:12 +00:00
1 parent 78cdaa9f29
commit e859e9cd9c
1 file changed
+25 -1
+25 -1
View File
@@ -48,6 +48,7 @@ import hudson.util.RingBufferLogHandler;
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;
@@ -261,13 +262,36 @@ public class WebAppMain implements ServletContextListener {
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) {
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) {