private void handleErrorsOnSave(@NotNull Map<Document, IOException> failures) {
    if (ApplicationManager.getApplication().isUnitTestMode()) {
      IOException ioException = ContainerUtil.getFirstItem(failures.values());
      if (ioException != null) throw new RuntimeException(ioException);
      return;
    }

    for (Map.Entry<Document, IOException> entry : failures.entrySet()) {
      LOG.warn("file: " + getFile(entry.getKey()), entry.getValue());
    }

    // later to get out of write action
    ApplicationManager.getApplication().invokeLater(() -> {
      String text = StringUtil.join(failures.values(), Throwable::getMessage, "\n");

      DialogWrapper dialog = new DialogWrapper((Project)null) {
        {
          init();
          setTitle(UIBundle.message("cannot.save.files.dialog.title"));
        }

        @Override
        protected void createDefaultActions() {
          super.createDefaultActions();
          myOKAction.putValue(Action.NAME, UIBundle
            .message(myOnClose ? "cannot.save.files.dialog.ignore.changes" : "cannot.save.files.dialog.revert.changes"));
          myOKAction.putValue(DEFAULT_ACTION, null);

          if (!myOnClose) {
            myCancelAction.putValue(Action.NAME, CommonBundle.getCloseButtonText());
          }
        }

        @Override
        protected JComponent createCenterPanel() {
          JPanel panel = new JPanel(new BorderLayout(0, 5));

          panel.add(new JLabel(UIBundle.message("cannot.save.files.dialog.message")), BorderLayout.NORTH);

          JTextPane area = new JTextPane();
          area.setText(text);
          area.setEditable(false);
          area.setMinimumSize(new Dimension(area.getMinimumSize().width, 50));
          panel.add(new JBScrollPane(area, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER),
                    BorderLayout.CENTER);

          return panel;
        }
      };

      if (dialog.showAndGet()) {
        for (Document document : failures.keySet()) {
          reloadFromDisk(document);
        }
      }
    });
  }
private void handleErrorsOnSave(@NotNull Map<Document, IOException> failures)