From f4b6817513da096f6563af79462ebe5af555f717 Mon Sep 17 00:00:00 2001 From: Nikita Iarychenko Date: Wed, 21 May 2025 10:52:18 +0400 Subject: [PATCH] OPENIDE #180 Buttons in Internal Error dialog don't work when OpenIDE starts --- .../ide/bootstrap/StartupErrorReporter.java | 83 +++++++++---------- 1 file changed, 41 insertions(+), 42 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/platform/ide/bootstrap/StartupErrorReporter.java b/platform/platform-impl/src/com/intellij/platform/ide/bootstrap/StartupErrorReporter.java index 08965fd587d6..8804f9ecb6a0 100644 --- a/platform/platform-impl/src/com/intellij/platform/ide/bootstrap/StartupErrorReporter.java +++ b/platform/platform-impl/src/com/intellij/platform/ide/bootstrap/StartupErrorReporter.java @@ -1,11 +1,15 @@ // Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// +// Modified by Nikita Iarychenko at 2025 as part of the OpenIDE project(https://openide.ru). +// Any modifications are available on the same license terms as the original source code. package com.intellij.platform.ide.bootstrap; import com.intellij.diagnostic.ImplementationConflictException; import com.intellij.diagnostic.LoadingState; import com.intellij.diagnostic.PluginException; import com.intellij.ide.BootstrapBundle; -import com.intellij.ide.logsUploader.LogUploader; +import com.intellij.ide.actions.RevealFileAction; +import com.intellij.ide.actions.ShowLogAction; import com.intellij.ide.plugins.EssentialPluginMissingException; import com.intellij.ide.plugins.PluginConflictReporter; import com.intellij.ide.plugins.PluginManagerCore; @@ -23,9 +27,7 @@ import com.intellij.openapi.diagnostic.ExceptionWithAttachments; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.util.NlsSafe; -import com.intellij.openapi.util.io.NioFiles; import com.intellij.util.io.Compressor; -import com.intellij.util.io.URLUtil; import org.jetbrains.annotations.*; import javax.swing.*; @@ -41,6 +43,7 @@ import java.nio.file.Path; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.concurrent.ExecutionException; +import java.util.function.Consumer; import static java.util.Objects.requireNonNullElse; import static org.jetbrains.annotations.Nls.Capitalization.Sentence; @@ -144,17 +147,25 @@ public final class StartupErrorReporter { supportCenter(); } }); + + var closeBtn = createTextBtn(BootstrapBundle.message("bootstrap.error.option.close"), e -> { + Component component = SwingUtilities.getRoot((Component) e.getSource()); + if (component instanceof JDialog) { + ((JDialog) component).dispose(); + } + }); + + var resetBtn = createTextBtn(BootstrapBundle.message("bootstrap.error.option.reset"), e -> cleanStart()); + + var showLogBtn = createTextBtn(ShowLogAction.getActionName(), e -> reportProblem(title, message, error)); + var options = new Object[]{ - BootstrapBundle.message("bootstrap.error.option.close"), - BootstrapBundle.message("bootstrap.error.option.reset"), - BootstrapBundle.message("bootstrap.error.option.report"), + closeBtn, + resetBtn, + showLogBtn, learnMore }; - var choice = JOptionPane.showOptionDialog(JOptionPane.getRootFrame(), prepareMessage(message), title, JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]); - switch (choice) { - case 1 -> cleanStart(); - case 2 -> reportProblem(title, message, error); - } + JOptionPane.showOptionDialog(JOptionPane.getRootFrame(), prepareMessage(message), title, JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]); } catch (Throwable t) { System.err.println("\n-----"); @@ -163,6 +174,17 @@ public final class StartupErrorReporter { } } + private static JButton createTextBtn(String text, Consumer onClick) { + var button = new JButton(text); + button.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + onClick.accept(e); + } + }); + return button; + } + private static void supportCenter() { try { var url = System.getProperty(SUPPORT_URL_PROPERTY, "https://jb.gg/ide/critical-startup-errors"); @@ -174,41 +196,17 @@ public final class StartupErrorReporter { } private static void reportProblem(String title, String description, @Nullable Throwable error) { - if (error != null) { - title += " (" + error.getClass().getSimpleName() + ": " + shorten(error.getMessage()) + ')'; - } - - var uploadId = (String)null; if (error instanceof ExceptionWithAttachments ewa) { - var message = prepareMessage(BootstrapBundle.message("bootstrap.error.message.confirm")); - var ok = JOptionPane.showConfirmDialog(JOptionPane.getRootFrame(), message, BootstrapBundle.message("bootstrap.error.option.report"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE); - if (ok != JOptionPane.OK_OPTION) return; - try { - uploadId = uploadLogs(ewa); + uploadLogs(ewa); } catch (Throwable t) { var buf = new StringWriter(); t.printStackTrace(new PrintWriter(buf)); - message = prepareMessage(BootstrapBundle.message("bootstrap.error.message.no.logs", buf)); + var message = prepareMessage(BootstrapBundle.message("bootstrap.error.message.no.logs", buf)); JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), message, BootstrapBundle.message("bootstrap.error.title.no.logs"), JOptionPane.ERROR_MESSAGE); - return; } } - if (uploadId != null) { - description += "\n\n-----\n[Upload ID: " + uploadId + ']'; - } - - try { - var url = System.getProperty(REPORT_URL_PROPERTY, "https://youtrack.jetbrains.com/newissue?project=IJPL&clearDraft=true&summary=$TITLE$&description=$DESCR$&c=$SUBSYSTEM$") - .replace("$TITLE$", URLUtil.encodeURIComponent(title)) - .replace("$DESCR$", URLUtil.encodeURIComponent(description)) - .replace("$SUBSYSTEM$", URLUtil.encodeURIComponent("Subsystem: IDE. Startup")); - Desktop.getDesktop().browse(new URI(url)); - } - catch (Throwable t) { - showBrowserError(t); - } } private static String shorten(String message) { @@ -238,13 +236,14 @@ public final class StartupErrorReporter { var worker = new SwingWorker() { @Override protected String doInBackground() throws Exception { - var logs = collectLogs(error); - try { - return LogUploader.uploadFile(logs); + var path = collectLogs(error); + if (RevealFileAction.isSupported()) { + RevealFileAction.openFile(path); } - finally { - NioFiles.deleteQuietly(logs); + else { + RevealFileAction.openDirectory(path); } + return ""; } @Override