public static void assertInvalidRanges(
      final int startOffset,
      final int newEndOffset,
      FormattingDocumentModel model,
      String message) {
    @NonNls final StringBuilder buffer = new StringBuilder();
    buffer.append("Invalid formatting blocks:").append(message).append("\n");
    buffer.append("Start offset:");
    buffer.append(startOffset);
    buffer.append(" end offset:");
    buffer.append(newEndOffset);
    buffer.append("\n");

    int minOffset = Math.max(Math.min(startOffset, newEndOffset) - 20, 0);
    int maxOffset = Math.min(Math.max(startOffset, newEndOffset) + 20, model.getTextLength());

    buffer
        .append("Affected text fragment:[")
        .append(minOffset)
        .append(",")
        .append(maxOffset)
        .append("] - '")
        .append(model.getText(new TextRange(minOffset, maxOffset)))
        .append("'\n");

    final StringBuilder messageBuffer = new StringBuilder();
    messageBuffer.append("Invalid ranges during formatting");
    if (model instanceof FormattingDocumentModelImpl) {
      messageBuffer
          .append(" in ")
          .append(((FormattingDocumentModelImpl) model).getFile().getLanguage());
    }

    buffer.append("File text:(").append(model.getTextLength()).append(")\n'");
    buffer.append(model.getText(new TextRange(0, model.getTextLength())).toString());
    buffer.append("'\n");
    buffer.append("model (").append(model.getClass()).append("): ").append(model);

    Throwable currentThrowable = new Throwable();
    if (model instanceof FormattingDocumentModelImpl) {
      final FormattingDocumentModelImpl modelImpl = (FormattingDocumentModelImpl) model;
      buffer.append("Psi Tree:\n");
      final PsiFile file = modelImpl.getFile();
      final List<PsiFile> roots = file.getViewProvider().getAllFiles();
      for (PsiFile root : roots) {
        buffer.append("Root ");
        DebugUtil.treeToBuffer(buffer, root.getNode(), 0, false, true, true, true);
      }
      buffer.append('\n');
      currentThrowable = makeLanguageStackTrace(currentThrowable, file);
    }

    LogMessageEx.error(LOG, messageBuffer.toString(), currentThrowable, buffer.toString());
  }
  private void error(String descr) {
    PsiFile file = myScope.getContainingFile();
    String fileText = file != null ? file.getText() : null;

    LogMessageEx.error(LOG, descr, myScope.getText(), "\n------------------\n", fileText);
  }
 public static void error(
     @NotNull Logger logger, @NonNls @NotNull String message, @NotNull String... attachmentText) {
   error(logger, message, new Throwable(), attachmentText);
 }