Alexander-Miller / treemacs

GNU General Public License v3.0
2.1k stars 154 forks source link

treemacs--process-file-events producing errors #749

Closed bestlem closed 10 months ago

bestlem commented 3 years ago

I am constantly getting the filewatch timer generating errors usually Error running timer ‘treemacs--process-file-events’: (wrong-type-argument sequencep t)

But can have a different wrong type.

This is with Aquamacs based on emacs 25.3.50.1 and on the macport of emacs GNU Emacs 27.1 (build 1, x86_64-apple-darwin18.7.0, Carbon Version 158 AppKit 1671.6) of 2020-11-12

treemacs from melpa - treemacs-20201128.1158 (and a few earlier versions) on macOS 10.14.6

In the latter I caught the backtrace I attach at the end.

What sort of information will help to track down the cause of my problem?

Mark

Backtrace.txt

Alexander-Miller commented 3 years ago

First try updating, the error may well have been a compiler blooper.

If that does not help head over to treemacs--recursive-refresh-descent and put the following line after the -when-let, re-eval the function and let me know what gets logged when you see an error.

      (treemacs-log "Change List %s %s" (treemacs-dom-node->key node) change-list)
Alexander-Miller commented 3 years ago

Bump?

bestlem commented 3 years ago

Sorry for delay.

It is not a simple compile issue as it occurs through several package upgrades and also on two versions of emacs and I separate elpa by having the version number in the elpa path.

ALso I stopped fiddling with my emacs setup for a bit and got less issues but a few chnages to init.el etc and get

In treemacs--process-file-events treemacs--in-this-buffer is nil Error running timer ‘treemacs--process-file-events’: (wrong-type-argument sequencep t)

Alexander-Miller commented 3 years ago

I'll need to see the log output from https://github.com/Alexander-Miller/treemacs/issues/749#issuecomment-745590387 to get a grip on what might be going on.

Trying to edebug treemacs--recursive-refresh-descent would be useful as well - just knowing which lines the error happens in would be a great help.

You can also try reproducing the problem with just treemacs. Clone the repo and run make clean-start (you'll also need to have cask installed). That'll start a bare Emacs with just treemacs and its dependencies installed. Try some of your usual workflows - if nothing happens it may be a problem with your config.

In treemacs--process-file-events treemacs--in-this-buffer is nil

That one shouldn't matter, it just means that the refresh timer runs when you're not in a treemacs window.

bestlem commented 3 years ago

The error is still there but with newer treemacs it looks different. The actual functionality of emacs and treemacs looks OK but the issue is that if I turn debug on error on it catches these.

backtrace is

  treemacs-without-recenter(nil)
  treemacs--recursive-refresh-descent(#s(treemacs-dom-node :key "/Users/mark/Sy..." :parent nil :children ... :reentry-nodes ... :position #<marker (moves after insertion) at 3 in  *Treemacs-Scoped-Buffer-#<frame Emacs@mini20.local 0x1349e9a00>*> :refresh-flag nil :collapse-keys nil) #s(treemacs-project :name "Aquamacs Emacs..." :path "/Users/mark/Sy..." :path-status local-readable :is-disabled? nil))
  treemacs--process-file-events()
  apply(treemacs--process-file-events nil)
  timer-event-handler([t 24767 18108 725587 nil treemacs--process-file-events nil nil 0])

A problem is that I can't see treemacs-without-recenter being called in treemacs--recursive-refresh-descent so I can't inspect more. My emacs knowledge is lacking - is this due to a lot of functions being define-inline and don't show up on the stack, if so is there an easy way to convert thenm to plain defuns so I can help debug?

Alexander-Miller commented 3 years ago

is there an easy way to convert thenm to plain defuns so I can help debug?

It's not quite straight forward. You'd have to switch define-inline to defun, remove the inline-letevals and inline-quote wrapping, take away the commas from the function's arguments in the body and finally re-evaluate the changed function and its call sites (or recompile and restart).

treemacs-without-recenter(nil)

That's a macro, so it shouldn't be part of a stack trace at all. All it does is expand into let-binding a single variable. Emacs thinking it's a function may be caused by either not restarting after updating treemacs, or just a plain compiler blooper (I've had reports of similar macro-is-a-function problems in the past). So try reinstalling treemacs and restarting - you most likely don't have to touch the inline stuff to fix this particular problem.

If the buffer-is-nil problem keeps happening the log as described in https://github.com/Alexander-Miller/treemacs/issues/749#issuecomment-745590387 is the way to go.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

hraban commented 1 year ago

Fwiw I'm running into this exact same problem and found this issue by googling the error message. Version:

    Version: 20230822.2039
     Commit: 8fec46a8717fb5b0eedfba39b4b6001cce1c7145

So it's not stale and shouldn't be closed

Alexander-Miller commented 1 year ago

So it's not stale and shouldn't be closed

Let's keep trying then.

Is your treemacs fully up to date? What does your stack trace look like? Do you also see the part about treemacs-without-recenter? Can you provide a sequence of events that leads to this error?

hraban commented 1 year ago

Thanks for your patience. I'll try to get a stack trace. It's taking a while because I don't know how to trigger this condition, so I need to run my entire emacs session with debug-on-error on. I actually encountered the error once and reflexively hit q 😩. Next time.

hraban commented 1 year ago

Ok finally got a traceback although it might not be this issue at all, but a totally unrelated one! Pasting it here for posterity:

Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
  treemacs--apply-annotations-deferred(#<marker (moves after insertion) at 240 in  *Treemacs-Scoped-Buffer-#<frame README.md 0x12907c230>*> "/Users/user/code/personal/cl-nix-lite/.github" #<buffer  *Treemacs-Scoped-Buffer-#<frame README.md 0x12907c230>*> #<process Process Future>)
  apply(treemacs--apply-annotations-deferred (#<marker (moves after insertion) at 240 in  *Treemacs-Scoped-Buffer-#<frame README.md 0x12907c230>*> "/Users/user/code/personal/cl-nix-lite/.github" #<buffer  *Treemacs-Scoped-Buffer-#<frame README.md 0x12907c230>*> #<process Process Future>))
  timer-event-handler([t 25900 38434 906640 nil treemacs--apply-annotations-deferred (#<marker (moves after insertion) at 240 in  *Treemacs-Scoped-Buffer-#<frame README.md 0x12907c230>*> "/Users/user/code/personal/cl-nix-lite/.github" #<buffer  *Treemacs-Scoped-Buffer-#<frame README.md 0x12907c230>*> #<process Process Future>) nil 0 nil])
  pfuture-await-to-finish(#<process Process Future<1>>)
  treemacs--parse-collapsed-dirs(#<process Process Future<1>>)
  treemacs--expand-dir-node(#<marker (moves after insertion) at 19 in  *Treemacs-Scoped-Buffer-#<frame README.md 0x12907c230>*> :git-future #<process Process Future<2>>)
  treemacs--reopen-node(#<marker (moves after insertion) at 19 in  *Treemacs-Scoped-Buffer-#<frame README.md 0x12907c230>*> #<process Process Future<2>>)
  treemacs--reentry("/Users/user/code/personal/cl-nix-lite" #<process Process Future<2>>)
  treemacs--expand-root-node(#<marker (moves after insertion) at 3 in  *Treemacs-Scoped-Buffer-#<frame README.md 0x12907c230>*> nil)
  treemacs-toggle-node()
  treemacs-project->refresh!(#s(treemacs-project :name "cl-nix-lite" :path "/Users/user/code/personal/cl-nix-lite" :path-status local-readable :is-disabled? nil))
  treemacs--do-refresh(#<buffer  *Treemacs-Scoped-Buffer-#<frame README.md 0x12907c230>*> #s(treemacs-project :name "cl-nix-lite" :path "/Users/user/code/personal/cl-nix-lite" :path-status local-readable :is-disabled? nil))
  treemacs-refresh()
  funcall-interactively(treemacs-refresh)
  command-execute(treemacs-refresh)
Alexander-Miller commented 1 year ago

Unfortunately I cannot say what's going on based on this stack trace. Whatever is amiss could have been caused by any number of previous events.

There is probably some combination of edits + git state + refresh + files layout steps that can cause this. If you manage to come up with such a recipe I'll be able to help properly.

stale[bot] commented 10 months ago

This issue has been automatically marked as stale because it has not had recent activity (this bot only works as a reminder, it will not close issues).

Alexander-Miller commented 10 months ago

Closing this on account of inactivity.

Feel free to re-open if this issue is still relevant.

hraban commented 10 months ago

fair enough 👍

hraban commented 8 months ago

Ah it happened again, but no debug mode so no traceback. Posting for posterity:

Error running timer ‘treemacs--process-file-events’: (wrong-type-argument symbolp "!")

Happened again a few minutes later, with traceback:

Debugger entered--Lisp error: (wrong-type-argument symbolp "!")
  treemacs-do-update-single-file-git-state("/usr/local/share/dotfiles/result")
  treemacs-update-single-file-git-state("/usr/local/share/dotfiles/result")
  treemacs--recursive-refresh-descent(#s(treemacs-dom-node :key "/usr/local/share/dot..." :parent nil :children (... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...) :reentry-nodes (...) :position #<marker (moves after insertion) at 334 in  *Treemacs-Scoped-Buffer-#<frame flake.nix<secrets-trampoline> 0x13ad1e430>*> :refresh-flag nil :collapse-keys nil) #s(treemacs-project :name "dotfiles" :path "/usr/local/share/dot..." :path-status local-readable :is-disabled? nil))
  treemacs--process-file-events()
  apply(treemacs--process-file-events nil)
  timer-event-handler([t 26066 6556 287707 nil treemacs--process-file-events nil nil 0 nil])

Note the file that treemacs is trying to read there, /result, is a symlink to the nix store which is a root-owned chmod 644/755 kinda folder, iow readable to the current user running emacs, but not owned nor writable by them.

hraban commented 8 months ago

It's probably due to this:

(let ((file "/usr/local/share/dotfiles/result"))
  (cl-remove-if (lambda (file) (symbolp (cl-second file)))
                (ht-items (ht-get treemacs--git-cache (treemacs--parent file)))))
(("/usr/local/share/dotfiles/result" "!")
 ("/usr/local/share/dotfiles/mac/flake.nix~" "!")
 ("/usr/local/share/dotfiles/.gitignore~" "!"))

How those got there, I wouldn't know.

I also realise this is probably a different issue from the original one, and this issue is at risk of becoming a kitchen sink for any error occurring in that file event handler function.

Alexander-Miller commented 8 months ago

("/usr/local/share/dotfiles/result" "!")

The change for this cache to contain faces instead of git status characters like "!" must be over a year old now. Do you have a very long-running Emacs session or did you update treemacs in-place? Are these just basic ignored files or are they contained in a directory that is also ignored, or are they "special" in any other way?

hraban commented 8 months ago

These are basic ignored files, ignored through a global .gitignore file, not a repo-local one.

[Treemacs] v3.1 (installed 2024.02.17) @ Emacs 29.2
Alexander-Miller commented 8 months ago

Hmm, the stack trace shows the error when updating a single file, let's check what it does. You can run the script like this:

 /home/am/Documents/git/treemacs master✔ 
 $ python /home/am/Documents/git/treemacs/src/scripts/treemacs-single-file-git-status.py /home/am/Documents/git/treemacs/src/elisp/treemacs-persistence.el "" /home/am/Documents/git/treemacs/src/elisp /home/am/Documents/git/treemacs/src /home/am/Documents/git/treemacs
(("/home/am/Documents/git/treemacs/src/elisp/treemacs-persistence.el" . treemacs-git-modified-face)("/home/am/Documents/git/treemacs/src/elisp" . treemacs-git-modified-face)("/home/am/Documents/git/treemacs/src" . treemacs-git-modified-face)("/home/am/Documents/git/treemacs" . treemacs-git-modified-face))

You need to call the treemacs-single-file-git-status from inside your project. First argument is the individual file. Second argument is the current face. You can just give it an empty string. The rest of the argument is the series of parent directories all the way to the root of your project. The output is an alist of files to faces.

hraban commented 8 months ago
(("/usr/local/share/dotfiles/result" . treemacs-git-ignored-face)("/usr/local/share/dotfiles" . treemacs-git-modified-face))

🤷‍♀️

I'll give it another go next time it happens.

Alexander-Miller commented 8 months ago

You can apply the following changes to log incorrect output:

modified   src/elisp/treemacs-async.el
@@ -299,9 +299,13 @@ OVERRIDE-STATUS: Boolean"
                    ;; first the file node with its own default face
                    (-let [output (read (pfuture-callback-output))]
                      (-let [(path . face) (pop output)]
+                       (unless (symbolp face)
+                         (treemacs-log "Non-face output '%s' for path '%s'" face path))
                        (treemacs--git-face-quick-change path face git-cache))
                      ;; then the directories
                      (pcase-dolist (`(,path . ,face) output)
+                       (unless (symbolp face)
+                         (treemacs-log "Non-face output '%s' for path '%s'" face path))
                        (treemacs--git-face-quick-change path face))))))))
           :on-error
           (progn

You'll need to recompile, delete the compiled files or override the entire function to make the changes stick.

Alexander-Miller commented 8 months ago

Never mind, I'm pretty sure I actually found the culprit. Making treemacs-hide-gitignored-files-mode work with the delayed git-mode implementation requires treemacs to pre-fetch your ignored files. That's where treemacs was still making the wrong git-cache entry (if only there was some way to statically type things, then this never would've happened).

So if you're using hide-gitignored-files-mode the problem will be solved now.

hraban commented 8 months ago

(if only there was some way to statically type things, then this never would've happened)

Truer words have never been spoken, my friend. Literally my thoughts as I was debugging this.

So if you're using hide-gitignored-files-mode the problem will be solved now.

I'll wait for the new version to hit my package manager and check in with you if a problem occurs anew!