public final void showError(@NotNull String message, @NotNull Throwable e) {
    if (getProject().isDisposed()) {
      return;
    }

    while (e instanceof InvocationTargetException) {
      if (e.getCause() == null) {
        break;
      }
      e = e.getCause();
    }

    ErrorInfo info = new ErrorInfo();
    info.myMessage = info.myDisplayMessage = message;
    info.myThrowable = e;
    configureError(info);

    if (info.myShowMessage) {
      showErrorPage(info);
    }
    if (info.myShowLog) {
      LOG.error(
          LogMessageEx.createEvent(
              info.myDisplayMessage,
              info.myMessage + "\n" + ExceptionUtil.getThrowableText(info.myThrowable),
              new Attachment(myFile)));
    } else {
      LOG.info(info.myDisplayMessage + "\n" + info.myMessage, info.myThrowable);
    }
  }
  /**
   * Clear the results and display notice to say an error occurred.
   *
   * @param error the error that occurred.
   */
  public void displayErrorResult(final Throwable error) {
    // match some friendly error messages.
    String errorText = null;
    if (error.getCause() != null && error.getCause() instanceof CheckstyleException) {

      for (final Pattern errorPattern : CHECKSTYLE_ERROR_PATTERNS.keySet()) {
        final Matcher errorMatcher = errorPattern.matcher(error.getCause().getMessage());
        if (errorMatcher.find()) {
          final Object[] args = new Object[errorMatcher.groupCount()];

          for (int i = 0; i < errorMatcher.groupCount(); ++i) {
            args[i] = errorMatcher.group(i + 1);
          }

          errorText = CheckStyleBundle.message(CHECKSTYLE_ERROR_PATTERNS.get(errorPattern), args);
        }
      }
    }

    if (errorText == null) {
      errorText = CheckStyleBundle.message("plugin.results.error");
    }

    treeModel.clear();
    treeModel.setRootText(errorText);

    clearProgress();
  }
Exemple #3
0
 /**
  * Returns a nice localized message for the passed exception in case it is possible, or toString()
  * otherwise.
  */
 static String getLocalizedMessage(Throwable e) {
   String localizedMessage;
   try {
     // try to load localized message
     if (e instanceof UserErrorException) {
       localizedMessage = e.getMessage();
     } else {
       String exceptionClassName = e.getClass().getSimpleName();
       String originalMessage = e.getMessage();
       localizedMessage =
           Labels.getLabel(
               "exception."
                   + exceptionClassName
                   + (originalMessage != null ? "." + originalMessage : ""));
     }
     // add cause summary, if it exists
     if (e.getCause() != null) {
       localizedMessage += "\n\n" + e.getCause().toString();
     }
     LOG.log(Level.FINE, "error", e);
   } catch (Exception e2) {
     // fallback to default text
     localizedMessage = e.toString();
     // output stack trace to the console
     LOG.log(Level.SEVERE, "unexpected error", e);
   }
   return localizedMessage;
 }
  public static void processException(Throwable t) {
    StartupAbortedException se = null;

    if (t instanceof StartupAbortedException) {
      se = (StartupAbortedException) t;
    } else if (t.getCause() instanceof StartupAbortedException) {
      se = (StartupAbortedException) t.getCause();
    } else if (!IdeaApplication.isLoaded()) {
      se = new StartupAbortedException(t);
    }

    if (se != null) {
      if (se.logError()) {
        try {
          if (Logger.isInitialized() && !(t instanceof ProcessCanceledException)) {
            getLogger().error(t);
          }
        } catch (Throwable ignore) {
        }

        Main.showMessage("Start Failed", t);
      }

      System.exit(se.exitCode());
    }

    if (!(t instanceof ProcessCanceledException)) {
      getLogger().error(t);
    }
  }
Exemple #5
0
  /**
   * The launching point
   *
   * <p>In development, pass the following on the JVM command line:
   * <tt>-Djava.util.logging.config.file=config/logging.properties</tt>
   *
   * <p>On Mac, add the following (otherwise SWT won't work): <tt>-XstartOnFirstThread</tt>
   */
  public static void main(String... args) {
    long startTime = System.currentTimeMillis();

    initSystemProperties();
    Display display;

    try {
      // this defines the Window class and app name on the Mac
      Display.setAppName(Version.NAME);
      display = Display.getDefault();
      LOG.finer("SWT initialized after " + (System.currentTimeMillis() - startTime));
    } catch (UnsatisfiedLinkError e) {
      JOptionPane.showMessageDialog(
          null,
          "Failed to load native code. Probably you are using a binary built for wrong OS or CPU - try downloading both 32-bit and 64-bit binaries");
      return;
    }

    // initialize Labels instance
    Labels.initialize(Locale.getDefault());
    // initialize Config instance
    Config globalConfig = Config.getConfig();
    LOG.finer("Labels and Config initialized after " + (System.currentTimeMillis() - startTime));

    ComponentRegistry componentRegistry = new ComponentRegistry();
    LOG.finer("ComponentRegistry initialized after " + (System.currentTimeMillis() - startTime));

    processCommandLine(args, componentRegistry);

    // create the main window using dependency injection
    MainWindow mainWindow = componentRegistry.getMainWindow();
    LOG.fine("Startup time: " + (System.currentTimeMillis() - startTime));

    while (!mainWindow.isDisposed()) {
      try {
        if (!display.readAndDispatch()) display.sleep();
      } catch (Throwable e) {
        if (e instanceof SWTException && e.getCause() != null) e = e.getCause();

        // display a nice error message
        String localizedMessage = getLocalizedMessage(e);
        Shell parent = display.getActiveShell();
        showMessage(
            parent != null ? parent : mainWindow.getShell(),
            e instanceof UserErrorException ? SWT.ICON_WARNING : SWT.ICON_ERROR,
            Labels.getLabel(e instanceof UserErrorException ? "text.userError" : "text.error"),
            localizedMessage);
      }
    }

    // save config on exit
    globalConfig.store();

    // dispose the native objects
    display.dispose();
  }
Exemple #6
0
 /** If the exception is wrapped, unwrap it. */
 public static Throwable getActualException(Throwable e) {
   if (e instanceof ExecutionException) e = e.getCause();
   if (e instanceof MBeanException
       || e instanceof RuntimeMBeanException
       || e instanceof RuntimeOperationsException
       || e instanceof ReflectionException) {
     Throwable t = e.getCause();
     if (t != null) return t;
   }
   return e;
 }
 private void logTrace(StringBuilder builder, Throwable e) {
   Throwable parent = e;
   String indent = "    ";
   while (parent != null) {
     if (parent == e) {
       builder.append(indent).append("Trace:").append("\n");
     } else {
       builder
           .append(indent)
           .append("Caused By: (")
           .append(parent.getClass().getSimpleName())
           .append(")")
           .append("\n");
       builder
           .append(indent)
           .append("    ")
           .append("[")
           .append(parent.getMessage())
           .append("]")
           .append("\n");
     }
     for (StackTraceElement ele : e.getStackTrace()) {
       builder.append(indent).append("    ").append(ele.toString()).append("\n");
     }
     indent += "    ";
     parent = parent.getCause();
   }
 }