Skip to content

Commit

Permalink
Allow plugins to override boot failure view (#8442)
Browse files Browse the repository at this point in the history
  • Loading branch information
timja authored Jan 5, 2024
1 parent 78cdaa9 commit e859e9c
Showing 1 changed file with 25 additions and 1 deletion.
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) {
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

0 comments on commit e859e9c

Please sign in to comment.