Org-capture: Capture template ‘d’: Cannot make side window the only window

This is my Emacs configuration

and I’m now getting this the error in subject when I try to create a new node.
Weirdly after I removed my whole .emacs.d and recreated it it was fixed, but today it’s broken again without really having done any changes.
Any idea what it could be?
I suspect it’s maybe related to treemacs, but changing the config there didn’t help yet, so maybe it’s something else.

Actually I could narrow it down, the problem is this function

(defun treemacs-enable-and-show ()
  (message "inside treemacs-enable-and-show")
  (when buffer-file-name
    (when (equal 'none (treemacs-current-visibility))

    (with-current-buffer (find-buffer-visiting buffer-file-name)
      (treemacs-display-current-project-exclusively))) )

Which is used a find-file-hook:
(add-hook 'find-file-hook 'treemacs-enable-and-show)

Not sure how to fix it though, org-capture is doing something weird apparently there when creating the buffer?

I’d suggest:

(remove-hook 'find-file-hook 'treemacs-enable-and-show)

Also try toggle-debug-on-error and see the backtrace. it should show a call stack, which helps you determine offending function and context.

Yeah sure I removed the hook, but I would like to enable it again once I fix it, since it’s quite useful.
Anyway this is the full error, and the file is actually created, and if I try to visit it a second time it works, I just can’t see see the right buffer when I do C-c n f for the first time.

  error("Capture template `%s': %s" "d" "Cannot make side window the only window")
  org-capture(nil "d")
  org-roam-capture-(:node #s(org-roam-node :file nil :file-title nil :file-hash nil :file-atime nil :file-mtime nil :id "2ed85b66-dc6f-4d5e-9f7a-4946f2dbe18f" :level nil :point nil :todo nil :priority nil :scheduled nil :deadline nil :title "check check again" :properties nil :olp nil :tags nil :aliases nil :refs nil) :templates nil :props (:finalize find-file :call-location #<marker at 1 in>))
  #<subr command-execute>(org-roam-node-find nil nil nil)
  ad-Advice-command-execute(#<subr command-execute> org-roam-node-find)
  apply(ad-Advice-command-execute #<subr command-execute> org-roam-node-find)

What seems to be happening is as follows:

  1. You star org-capture via org-roam-node-find
  2. Emacs opens a capture buffer
  3. At the same time, Emacs opens a treemacs buffer as a side-buffer via find-file-hook
  4. You complete the capture peocess
  5. Emacs tries to close the capture buffer
  6. Emacs errors because side-buffer cannot be threonly buffer in a frame

If this is indeed what is happening then, you can just have a conditional in your the function set in find-file-hook to avoid opening treemacs for the capture buffer.

To test the idea, it should be trivial to modify the initial conditional in this function and check if the buffer-name contains “CAPTURE”.