Example usage for com.intellij.openapi.diagnostic IdeaLoggingEvent getThrowable

List of usage examples for com.intellij.openapi.diagnostic IdeaLoggingEvent getThrowable

Introduction

In this page you can find the example usage for com.intellij.openapi.diagnostic IdeaLoggingEvent getThrowable.

Prototype

public Throwable getThrowable() 

Source Link

Usage

From source file:bazaar4idea.util.BzrErrorReportSubmitter.java

License:Apache License

/**
 * @noinspection ThrowablePrintStackTrace,ThrowableResultOfMethodCallIgnored
 *///from   w w w  .ja  va 2  s.  c om
private static SubmittedReportInfo sendError(IdeaLoggingEvent event, Component parentComponent) {
    NotifierBean notifierBean = new NotifierBean();
    ErrorBean errorBean = new ErrorBean();
    errorBean.autoInit();
    //    errorBean.setLastAction(IdeaLogger.ourLastActionId);

    int threadId = 0;
    SubmittedReportInfo.SubmissionStatus submissionStatus = SubmittedReportInfo.SubmissionStatus.FAILED;

    final DataContext dataContext = DataManager.getInstance().getDataContext(parentComponent);
    Project project = PlatformDataKeys.PROJECT.getData(dataContext);

    String description = "";
    do {
        // prepare
        try {
            ErrorReportSender sender = ErrorReportSender.getInstance();
            //
            sender.prepareError(project, event.getThrowable());
            //
            BzrSendErrorForm dlg = new BzrSendErrorForm();
            dlg.setErrorDescription(description);
            dlg.show();

            BzrErrorReportConfigurable reportConf = BzrErrorReportConfigurable.getInstance();
            @NonNls
            String senderEmail = reportConf.EMAIL_ADDRESS;
            @NonNls
            String smtpServer = reportConf.SMTP_SERVER;
            @NonNls
            String itnLogin = reportConf.AUTH_USERNAME;
            @NonNls
            String itnPassword = reportConf.getPlainItnPassword();
            notifierBean.setEmailAddress(senderEmail);
            notifierBean.setSmtpServer(smtpServer);
            notifierBean.setItnLogin(itnLogin);
            notifierBean.setItnPassword(itnPassword);
            //
            description = dlg.getErrorDescription();
            String message = event.getMessage();
            //
            @NonNls
            StringBuilder descBuilder = new StringBuilder();
            if (description.length() > 0) {
                descBuilder.append("User description: ").append(description).append("\n");
            }
            if (message != null) {
                descBuilder.append("Error message: ").append(message).append("\n");
            }

            Throwable t = event.getThrowable();
            if (t != null) {
                //          final PluginId pluginId = IdeErrorsDialog.findPluginId(t);
                //          if (pluginId != null) {
                //            final IdeaPluginDescriptor ideaPluginDescriptor = ApplicationManager.getApplication().getPlugin(pluginId);
                //            if (ideaPluginDescriptor != null && !ideaPluginDescriptor.isBundled()) {
                //              descBuilder.append("Plugin version: ").append(ideaPluginDescriptor.getVersion()).append("\n");
                //            }
                //          }
            }

            if (previousExceptionThreadId != 0) {
                descBuilder.append("Previous exception is: ").append(URL_HEADER)
                        .append(previousExceptionThreadId).append("\n");
            }
            if (wasException) {
                descBuilder.append("There was at least one exception before this one.\n");
            }

            errorBean.setDescription(descBuilder.toString());

            if (dlg.isShouldSend()) {
                threadId = sender.sendError(notifierBean, errorBean);
                previousExceptionThreadId = threadId;
                wasException = true;
                submissionStatus = SubmittedReportInfo.SubmissionStatus.NEW_ISSUE;

                Messages.showInfoMessage(parentComponent, BzrBundle.message("error.report.confirmation"),
                        ERROR_REPORT);
                break;
            } else {
                break;
            }

            //      } catch (NoSuchEAPUserException e) {
            //        if (Messages.showYesNoDialog(parentComponent, DiagnosticBundle.message("error.report.authentication.failed"),
            //                                     ReportMessages.ERROR_REPORT, Messages.getErrorIcon()) != 0) {
            //          break;
            //        }
            //      } catch (InternalEAPException e) {
            //        if (Messages.showYesNoDialog(parentComponent, DiagnosticBundle.message("error.report.posting.failed", e.getMessage()),
            //                                     ReportMessages.ERROR_REPORT, Messages.getErrorIcon()) != 0) {
            //          break;
            //        }
            //      } catch (IOException e) {
            //        if (!IOExceptionDialog.showErrorDialog(BzrVcsMessages.message("error.report.exception.title"),
            //                                               BzrVcsMessages.message("error.report.failure.message"))) {
            //          break;
            //        }
            //      } catch (NewBuildException e) {
            //        Messages.showMessageDialog(parentComponent,
            //                                   DiagnosticBundle.message("error.report.new.eap.build.message", e.getMessage()), CommonBundle.getWarningTitle(),
            //                                   Messages.getWarningIcon());
            //        break;
        } catch (Exception e) {
            LOG.info(e);
            if (Messages.showYesNoDialog(JOptionPane.getRootFrame(),
                    BzrBundle.message("error.report.sending.failure"), ERROR_REPORT,
                    Messages.getErrorIcon()) != 0) {
                break;
            }
        }

    } while (true);

    return new SubmittedReportInfo(
            submissionStatus != SubmittedReportInfo.SubmissionStatus.FAILED ? URL_HEADER + threadId : null,
            String.valueOf(threadId), submissionStatus);
}

From source file:com.android.tools.idea.diagnostics.error.ErrorReporter.java

License:Apache License

private static boolean sendError(IdeaLoggingEvent event, String additionalInfo, final Component parentComponent,
        final Consumer<SubmittedReportInfo> callback) {
    ErrorBean errorBean = new ErrorBean(event.getThrowable(), IdeaLogger.ourLastActionId);

    return doSubmit(event, parentComponent, callback, errorBean, additionalInfo);
}

From source file:com.android.tools.idea.diagnostics.error.ErrorReporter.java

License:Apache License

private static boolean doSubmit(final IdeaLoggingEvent event, final Component parentComponent,
        final Consumer<SubmittedReportInfo> callback, final ErrorBean bean, final String description) {
    final DataContext dataContext = DataManager.getInstance().getDataContext(parentComponent);

    bean.setDescription(description);//www  . ja  v a  2 s.co  m
    bean.setMessage(event.getMessage());

    Throwable t = event.getThrowable();
    if (t != null) {
        final PluginId pluginId = IdeErrorsDialog.findPluginId(t);
        if (pluginId != null) {
            final IdeaPluginDescriptor ideaPluginDescriptor = PluginManager.getPlugin(pluginId);
            if (ideaPluginDescriptor != null && !ideaPluginDescriptor.isBundled()) {
                bean.setPluginName(ideaPluginDescriptor.getName());
                bean.setPluginVersion(ideaPluginDescriptor.getVersion());
            }
        }
    }

    Object data = event.getData();

    if (data instanceof LogMessageEx) {
        bean.setAttachments(((LogMessageEx) data).getAttachments());
    }

    List<Pair<String, String>> kv = IdeaITNProxy.getKeyValuePairs(null, null, bean,
            IdeaLogger.getOurCompilationTimestamp(), ApplicationManager.getApplication(),
            (ApplicationInfoEx) ApplicationInfo.getInstance(), ApplicationNamesInfo.getInstance(),
            UpdateSettings.getInstance());

    final Project project = PlatformDataKeys.PROJECT.getData(dataContext);

    Consumer<String> successCallback = new Consumer<String>() {
        @Override
        public void consume(String token) {
            final SubmittedReportInfo reportInfo = new SubmittedReportInfo(null, "Issue " + token,
                    SubmittedReportInfo.SubmissionStatus.NEW_ISSUE);
            callback.consume(reportInfo);

            ReportMessages.GROUP.createNotification(ReportMessages.ERROR_REPORT, "Submitted",
                    NotificationType.INFORMATION, null).setImportant(false).notify(project);
        }
    };

    Consumer<Exception> errorCallback = new Consumer<Exception>() {
        @Override
        public void consume(Exception e) {
            // TODO: check for updates
            String message = AndroidBundle.message("error.report.at.b.android", e.getMessage());
            NotificationListener listener = new NotificationListener.UrlOpeningListener(true);
            ReportMessages.GROUP
                    .createNotification(ReportMessages.ERROR_REPORT, message, NotificationType.ERROR, listener)
                    .setImportant(false).notify(project);
        }
    };
    AnonymousFeedbackTask task = new AnonymousFeedbackTask(project, "Submitting error report", true, t,
            pair2map(kv), bean.getMessage(), bean.getDescription(),
            ApplicationInfo.getInstance().getFullVersion(), successCallback, errorCallback);
    if (project == null) {
        task.run(new EmptyProgressIndicator());
    } else {
        ProgressManager.getInstance().run(task);
    }
    return true;
}

From source file:com.google.cloud.tools.intellij.feedback.GoogleFeedbackErrorReporter.java

License:Apache License

private static boolean doSubmit(final IdeaLoggingEvent event, final Component parentComponent,
        final Consumer<SubmittedReportInfo> callback, final ErrorBean error, final String description) {
    error.setDescription(description);//from w w  w  . j a  v a 2s .  c om
    error.setMessage(event.getMessage());

    configureErrorFromEvent(event, error);

    ApplicationNamesInfo intelliJAppNameInfo = ApplicationNamesInfo.getInstance();
    ApplicationInfoEx intelliJAppExtendedInfo = ApplicationInfoEx.getInstanceEx();

    Map<String, String> params = buildKeyValuesMap(error, intelliJAppNameInfo, intelliJAppExtendedInfo,
            ApplicationManager.getApplication());

    DataContext dataContext = DataManager.getInstance().getDataContext(parentComponent);
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);

    Consumer<String> successCallback = new Consumer<String>() {
        @Override
        public void consume(String token) {
            final SubmittedReportInfo reportInfo = new SubmittedReportInfo(null, "Issue " + token,
                    SubmittedReportInfo.SubmissionStatus.NEW_ISSUE);
            callback.consume(reportInfo);

            ReportMessages.GROUP.createNotification(ReportMessages.ERROR_REPORT, "Submitted",
                    NotificationType.INFORMATION, null).setImportant(false).notify(project);
        }
    };

    Consumer<Exception> errorCallback = new Consumer<Exception>() {
        @Override
        public void consume(Exception ex) {
            String message = ErrorReporterBundle.message("error.googlefeedback.error", ex.getMessage());
            ReportMessages.GROUP.createNotification(ReportMessages.ERROR_REPORT, message,
                    NotificationType.ERROR, NotificationListener.URL_OPENING_LISTENER).setImportant(false)
                    .notify(project);
        }
    };
    GoogleAnonymousFeedbackTask task = new GoogleAnonymousFeedbackTask(project, "Submitting error report", true,
            event.getThrowable(), params, error.getMessage(), error.getDescription(),
            ApplicationInfo.getInstance().getFullVersion(), successCallback, errorCallback);
    if (project == null) {
        task.run(new EmptyProgressIndicator());
    } else {
        ProgressManager.getInstance().run(task);
    }
    return true;
}

From source file:com.google.cloud.tools.intellij.feedback.GoogleFeedbackErrorReporter.java

License:Apache License

private static void configureErrorFromEvent(IdeaLoggingEvent event, ErrorBean error) {
    Throwable throwable = event.getThrowable();
    if (throwable != null) {
        PluginId pluginId = IdeErrorsDialog.findPluginId(throwable);
        if (pluginId != null) {
            IdeaPluginDescriptor ideaPluginDescriptor = PluginManager.getPlugin(pluginId);
            if (ideaPluginDescriptor != null && !ideaPluginDescriptor.isBundled()) {
                error.setPluginName(ideaPluginDescriptor.getName());
                error.setPluginVersion(ideaPluginDescriptor.getVersion());
            }/*w  w w  . j a va2 s.  c  o m*/
        }
    }

    Object data = event.getData();

    if (data instanceof AbstractMessage) {
        error.setAttachments(((AbstractMessage) data).getAttachments());
    }
}

From source file:com.intellij.diagnostic.DefaultIdeaErrorLogger.java

License:Apache License

public boolean canHandle(IdeaLoggingEvent event) {
    if (ourLoggerBroken)
        return false;

    try {/*from w  w  w  .  j av  a 2s . c o m*/
        boolean notificationEnabled = !DISABLED_VALUE
                .equals(System.getProperty(FATAL_ERROR_NOTIFICATION_PROPERTY, ENABLED_VALUE));

        ErrorReportSubmitter submitter = IdeErrorsDialog.getSubmitter(event.getThrowable());
        boolean showPluginError = !(submitter instanceof ITNReporter2) /*|| ((ITNReporter)submitter).showErrorInRelease(event)*/;

        //noinspection ThrowableResultOfMethodCallIgnored
        return notificationEnabled || showPluginError || ApplicationManagerEx.getApplicationEx().isInternal()
                || isOOMError(event.getThrowable()) || event.getThrowable() instanceof MappingFailedException;
    } catch (LinkageError e) {
        if (e.getMessage().contains("Could not initialize class com.intellij.diagnostic.IdeErrorsDialog")) {
            //noinspection AssignmentToStaticFieldFromInstanceMethod
            ourLoggerBroken = true;
        }
        throw e;
    }
}

From source file:com.intellij.diagnostic.DefaultIdeaErrorLogger.java

License:Apache License

public void handle(IdeaLoggingEvent event) {
    if (ourLoggerBroken)
        return;// ww  w.j  a v a  2s  .c  om

    try {
        Throwable throwable = event.getThrowable();
        if (isOOMError(throwable)) {
            processOOMError(throwable);
        } else if (throwable instanceof MappingFailedException) {
            processMappingFailed(event);
        } else if (!ourOomOccurred) {
            MessagePool messagePool = MessagePool.getInstance();
            LogMessage message = messagePool.addIdeFatalMessage(event);
            if (message != null && ApplicationManager.getApplication() != null) {
                ErrorNotifier.notifyUi(message, messagePool);
            }
        }
    } catch (Throwable e) {
        String message = e.getMessage();
        //noinspection InstanceofCatchParameter
        if (message != null
                && message.contains("Could not initialize class com.intellij.diagnostic.MessagePool")
                || e instanceof NullPointerException && ApplicationManager.getApplication() == null) {
            //noinspection AssignmentToStaticFieldFromInstanceMethod
            ourLoggerBroken = true;
        }
    }
}

From source file:com.intellij.diagnostic.DefaultIdeaErrorLogger.java

License:Apache License

private static void processMappingFailed(final IdeaLoggingEvent event)
        throws InterruptedException, InvocationTargetException {
    if (!ourMappingFailedNotificationPosted && SystemInfo.isWindows && SystemInfo.is32Bit) {
        ourMappingFailedNotificationPosted = true;
        @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
        String exceptionMessage = event.getThrowable().getMessage();
        String text = exceptionMessage
                + "<br>Possible cause: unable to allocate continuous memory chunk of necessary size.<br>"
                + "Reducing JVM maximum heap size (-Xmx) may help.";
        Notifications.Bus.notify(/*from  w ww .j  a v a  2s.c  o m*/
                new Notification("Memory", "Memory Mapping Failed", text, NotificationType.WARNING), null);
    }
}

From source file:com.intellij.diagnostic.ITNReporter.java

License:Apache License

private SubmittedReportInfo doSubmit(IdeaLoggingEvent[] ideaLoggingEvents, String addInfo,
        Component component) {//  w ww.  j  a v a 2  s  .c o m
    final DataContext dataContext = DataManager.getInstance().getDataContext(component);
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    final IdeaLoggingEvent ideaLoggingEvent = ideaLoggingEvents[0];
    final String throwableText = ideaLoggingEvent.getThrowableText();
    String description = throwableText.substring(0, Math.min(Math.max(80, throwableText.length()), 80));

    @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
    Integer signature = ideaLoggingEvent.getThrowable().getStackTrace()[0].hashCode();

    String existing = findExisting(signature);
    if (existing != null) {
        final SubmittedReportInfo reportInfo = new SubmittedReportInfo(SERVER_URL + "issue/" + existing,
                existing, DUPLICATE);
        popupResultInfo(reportInfo, project);
        return reportInfo;
    }

    @NonNls
    StringBuilder descBuilder = new StringBuilder();

    descBuilder.append("Build: ").append(ApplicationInfo.getInstance().getBuild()).append('\n');
    descBuilder.append("OS: ").append(SystemInfo.OS_NAME).append(" ").append(SystemInfo.OS_ARCH).append(" ")
            .append(SystemInfo.OS_VERSION).append('\n');
    descBuilder.append("Java Vendor: ").append(SystemProperties.getJavaVmVendor()).append('\n');
    descBuilder.append("Java Version: ").append(SystemInfo.JAVA_VERSION).append('\n');
    descBuilder.append("Java Arch: ").append(SystemInfo.ARCH_DATA_MODEL).append('\n');
    descBuilder.append("Java Runtime Version: ").append(SystemInfo.JAVA_RUNTIME_VERSION).append('\n');

    String affectedVersion = null;
    Throwable t = ideaLoggingEvent.getThrowable();
    final PluginId pluginId = IdeErrorsDialog.findPluginId(t);
    if (pluginId != null) {
        final IdeaPluginDescriptor ideaPluginDescriptor = PluginManager.getPlugin(pluginId);
        if (ideaPluginDescriptor != null) {
            descBuilder.append("Plugin ").append(ideaPluginDescriptor.getName()).append(" version: ")
                    .append(ideaPluginDescriptor.getVersion()).append("\n");
            affectedVersion = ideaPluginDescriptor.getVersion();
        }
    }

    if (addInfo == null) {
        addInfo = "<none>";
    }

    descBuilder.append("Description: ").append(addInfo);

    for (IdeaLoggingEvent e : ideaLoggingEvents) {
        descBuilder.append("\n\n").append(e.toString());
    }

    String result = submit(description, descBuilder.toString(), affectedVersion);
    LOGGER.info("Error submitted, response: " + result);

    if (result == null) {
        return new SubmittedReportInfo(SERVER_ISSUE_URL, "", FAILED);
    }

    String ResultString = null;
    try {
        Pattern regex = Pattern.compile("id=\"([^\"]+)\"", Pattern.DOTALL | Pattern.MULTILINE);
        Matcher regexMatcher = regex.matcher(result);
        if (regexMatcher.find()) {
            ResultString = regexMatcher.group(1);
        }
    } catch (PatternSyntaxException ex) {
        // Syntax error in the regular expression
    }

    SubmittedReportInfo.SubmissionStatus status = NEW_ISSUE;

    if (ResultString == null) {
        return new SubmittedReportInfo(SERVER_ISSUE_URL, "", FAILED);
    }

    final SubmittedReportInfo reportInfo = new SubmittedReportInfo(SERVER_URL + "issue/" + ResultString,
            ResultString, status);

    /* Now try to set the autosubmit user using a custom command */
    /* if (user != null) {
       runCommand(ResultString, "Autosubmit User " + user);
     }  */

    if (signature != 0) {
        runCommand(ResultString, "Exception Signature " + signature);
    }

    popupResultInfo(reportInfo, project);

    return reportInfo;
}

From source file:com.intellij.diagnostic.ITNReporter2.java

License:Apache License

/**
 * @noinspection ThrowablePrintStackTrace
 *///from  ww w  .  java2s.c o  m
private static boolean sendError(IdeaLoggingEvent event, String additionalInfo, final Component parentComponent,
        final Consumer<SubmittedReportInfo> callback) {
    ErrorBean errorBean = new ErrorBean(event.getThrowable(), IdeaLogger.ourLastActionId);

    return doSubmit(event, parentComponent, callback, errorBean, additionalInfo);
}