holgerbrandl / pasteimages

An Intellij IDEA plugin to paste images from clipboard directly into a markdown docuement
BSD 2-Clause "Simplified" License
70 stars 21 forks source link

java.lang.Throwable: Do not call synchronous repository update in EDT #28

Open holgerbrandl opened 3 years ago

holgerbrandl commented 3 years ago
java.lang.Throwable: Do not call synchronous repository update in EDT
    at com.intellij.openapi.diagnostic.Logger.error(Logger.java:161)
    at com.intellij.dvcs.repo.VcsRepositoryManager.getRepositoryForRoot(VcsRepositoryManager.java:182)
    at com.intellij.dvcs.repo.VcsRepositoryManager.getRepositoryForRoot(VcsRepositoryManager.java:172)
    at com.intellij.dvcs.repo.VcsRepositoryManager.getRepositoryForFile(VcsRepositoryManager.java:136)
    at com.intellij.dvcs.repo.VcsRepositoryManager.getRepositoryForFile(VcsRepositoryManager.java:123)
    at com.intellij.dvcs.repo.AbstractRepositoryManager.getRepositoryForFile(AbstractRepositoryManager.java:63)
    at git4idea.GitUtil.sortFilesByRepository(GitUtil.java:285)
    at git4idea.GitUtil.sortFilesByGitRoot(GitUtil.java:240)
    at git4idea.GitUtil.sortFilesByGitRoot(GitUtil.java:194)
    at git4idea.checkin.GitCheckinEnvironment.scheduleUnversionedFilesForAddition(GitCheckinEnvironment.java:1063)
    at img2md.PasteImageFromClipboard.actionPerformed(PasteImageFromClipboard.java:151)
    at img2md.PasteImageHandler.doExecute(PasteImageHandler.java:79)
    at com.intellij.openapi.editor.actionSystem.DynamicEditorActionHandler.doExecute(DynamicEditorActionHandler.java:52)
    at com.intellij.openapi.editor.actionSystem.EditorActionHandler.lambda$execute$4(EditorActionHandler.java:199)
    at com.intellij.openapi.editor.actionSystem.EditorActionHandler.doIfEnabled(EditorActionHandler.java:89)
    at com.intellij.openapi.editor.actionSystem.EditorActionHandler.execute(EditorActionHandler.java:198)
    at com.intellij.openapi.editor.actionSystem.EditorAction.lambda$actionPerformed$0(EditorAction.java:89)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:216)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:172)
    at com.intellij.openapi.editor.actionSystem.EditorAction.actionPerformed(EditorAction.java:98)
    at com.intellij.openapi.editor.actionSystem.EditorAction.actionPerformed(EditorAction.java:73)
    at com.intellij.openapi.actionSystem.ex.ActionUtil.lambda$performActionDumbAware$5(ActionUtil.java:273)
    at com.intellij.util.SlowOperations.lambda$allowSlowOperations$0(SlowOperations.java:77)
    at com.intellij.util.SlowOperations.allowSlowOperations(SlowOperations.java:64)
    at com.intellij.util.SlowOperations.allowSlowOperations(SlowOperations.java:76)
    at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:273)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher$1.performAction(IdeKeyEventDispatcher.java:616)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.lambda$processAction$3(IdeKeyEventDispatcher.java:676)
    at com.intellij.openapi.application.TransactionGuardImpl.performUserActivity(TransactionGuardImpl.java:95)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.java:675)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.java:626)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processActionOrWaitSecondStroke(IdeKeyEventDispatcher.java:486)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.inInitState(IdeKeyEventDispatcher.java:481)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.java:232)
    at com.intellij.ide.IdeEventQueue.dispatchKeyEvent(IdeEventQueue.java:889)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:833)
    at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:449)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:808)
    at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$9(IdeEventQueue.java:448)
    at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:781)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:502)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
sagarv1 commented 3 years ago

I am also getting the same list of exception while pasting image in markdown using this plugin in Intellij idea

paulyt-cyber-lab commented 3 years ago

I've been hacking at this for a couple of days and thought I'd share my results...

Note: I have a lot of experience with programming but not in Java and the development environment I hacked together is not without issue. Hopefully this will still be of use!

The svn4idea plugin performs the scheduleUnversionedFilesForAddition() by adding files through background tasks but the git4idea plugin does not so, as a work around, I tried replacing the following code in PasteImageFromClipboard.java:

153. usedVcs.getCheckinEnvironment().scheduleUnversionedFilesForAddition(Collections.singletonList(fileByPath));

with:

153. new Task.Backgroundable(ed.getProject(), "scheduleUnversionedFilesForAddition", false) {
154.    @Override
155.     public void run(@NotNull ProgressIndicator indicator) {
156.        usedVcs.getCheckinEnvironment().scheduleUnversionedFilesForAddition(Collections.singletonList(fileByPath));
157.   }
158. }.queue();

and added:

13. import com.intellij.openapi.progress.Task;
14. import com.intellij.openapi.progress.ProgressIndicator;

This seems to work as best as I can test it (I get an error loading IDEA but it is, I think, because of my dev env) but I can't test it properly so thought I'd share with you in the hope that you can...

I don't know if any of this helps you with fixing the issue but I hope so 'cause I really want to use the plugin!

I think that, ultimately, the problem lies in the git4idea plugin...

Best Regards, Paul T.

holgerbrandl commented 3 years ago

Thanks for the great analysis. I have also prepared an update in PasteImageFromClipboard:

  if (usedVcs != null && usedVcs.getCheckinEnvironment() != null) {
            ApplicationManager.getApplication().executeOnPooledThread(() -> {
                usedVcs.getCheckinEnvironment().scheduleUnversionedFilesForAddition(Collections.singletonList(fileByPath));
            });
        }

So as you suggested putting the check into a thread seems to work around the issue. I'll keep running this patched version for a few more days before pushing out the plugin update.

paulyt-cyber-lab commented 3 years ago

So mine was definitely an over complicated way 😀

Once you push the plugin I’ll give it a spin 👍

paulyt-cyber-lab commented 3 years ago

Tested update and seems to be working 👍

metaMMA commented 1 year ago

This issue can be closed, @holgerbrandl