Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a .projectile file causes "projectile-invalidate-cache: Wrong type argument: hash-table-p, nil" #1854

Closed
jwr opened this issue Aug 1, 2023 · 12 comments

Comments

@jwr
Copy link

jwr commented Aug 1, 2023

Expected behavior

Adding a .projectile file to the root of a project should not stop projectile-find-file from working.

Actual behavior

Adding a .projectile file (either empty or containing excluded directories) to the root of a project causes projectile-find-file to fail with "Wrong type argument: hash-table-p, nil"

Steps to reproduce the problem

Add a .projectile file
run projectile-find-file

Environment & Version information

Projectile version information

Projectile 2.7.0

Emacs version

Emacs 29.1.50, earlier also on Emacs 28

Operating system

Mac OS 12.6.7

@Pacane
Copy link

Pacane commented Oct 5, 2023

I'm also hitting this issue. Do you have any workaround so far @jwr ?

@jwr
Copy link
Author

jwr commented Oct 5, 2023

Unfortunately, no. I learned to live with it and the pain of projectile-find-file listing a ton of irrelevant stuff.

Copy link

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed soon if no further activity occurs. Thank you for your contribution and understanding!

@github-actions github-actions bot added the Stale label Jan 26, 2025
@jwr
Copy link
Author

jwr commented Jan 26, 2025

This issue still exists for me. Emacs 29.1, Projectile 2.8.0, macOS 15.1.1.

I sadly cannot use a .projectile file to limit what gets considered for opening.

@jwr
Copy link
Author

jwr commented Jan 26, 2025

Here is a backtrace:

Debugger entered--Lisp error: (wrong-type-argument hash-table-p nil)
  remhash("/Users/jwr/Sync/code/" nil)
  projectile-invalidate-cache(nil)
  projectile-maybe-invalidate-cache(nil)
  (if (and (eq projectile-require-project-root 'prompt) (not (projectile-project-p))) (counsel-projectile-find-file-action-switch-project) (projectile-maybe-invalidate-cache arg) (+projectile-find-file--initialize) (let* ((project-files (+projectile-find-file--sort-file-with-scores (projectile-current-project-files))) (filename (completing-read (projectile-prepend-project-name "Find file: ") project-files nil t))) (if filename (progn (find-file (projectile-expand-root filename)))) (if nil (progn (ivy-read (projectile-prepend-project-name "Find file: ") project-files :matcher #'+projectile-find-file--matcher :require-match t :action counsel-projectile-find-file-action :caller '+projectile-find-file)))))
  +projectile-find-file(nil)
  funcall-interactively(+projectile-find-file nil)
  call-interactively(+projectile-find-file nil nil)
  command-execute(+projectile-find-file)

@bbatsov
Copy link
Owner

bbatsov commented Jan 30, 2025

The problem seems to be triggered by:

(defun projectile-maybe-invalidate-cache (force)
  "Invalidate if FORCE or project's dirconfig newer than cache."
  (when (or force (file-newer-than-file-p (projectile-dirconfig-file)
                                          projectile-cache-file))
    (projectile-invalidate-cache nil)))

I'm puzzled how this happens in your case, though, as without a cache file this should never enter the projectile-invalidate-cache command when the error occurs.

@bbatsov
Copy link
Owner

bbatsov commented Jan 30, 2025

I think I have a pretty good guess as to what's going on here. Would I be right if I assumed you're not using projectile-mode? I'm asking because I see some cache init logic is there and I'm guessing things break for people not using projectile-mode directly. Should be an easy fix, provided that's the root cause.

@jwr
Copy link
Author

jwr commented Jan 30, 2025

First, my apologies for an egg-on-face moment: what I initially reported was not about projectile-find-file, but about +projectile-find-file, which is part of a horrible hack to the default ranking of files in projectile. I've been using that code for years, as it vastly improves my experience with projectile-find-file. Notice the + in the backtraces above…

However.

When I use the actual projectile-find-file I can also reproduce the error. With your hint, I was able to debug and find out why projectile-invalidate-cache is called. It's because if I create a .projectile file (empty) in the current project, file-newer-than-file-p gets called with that .projectile file and projectile-cache-file which is ~/.emacs.d/projectile.cache which doesn't exist in my filesystem. file-newer-than-file-p returns t in this case, which causes the call to projectile-invalidate-cache.

If I touch ~/.emacs.d/projectile.cache, the problem disappears.

In other words: my initial report was garbage, but the problem still exists, even though I am not using the cache.

@jwr
Copy link
Author

jwr commented Jan 30, 2025

I think I have a pretty good guess as to what's going on here. Would I be right if I assumed you're not using projectile-mode?

That… is a trickier question than I imagined.

I never explicitly call projectile-mode and projectile-mode variable is nil.

but this is how I initialize projectile:

(use-package projectile
  :config
  (setq projectile-global-mode t
		projectile-current-dir-priority t
		projectile-sort-order 'modification-time))

@bbatsov
Copy link
Owner

bbatsov commented Jan 30, 2025

I did some changes to the caching logic in 5061bd8 that I believe should solve your problem (amongst other problems).

@bbatsov
Copy link
Owner

bbatsov commented Jan 31, 2025

At any rate - I think my last round of changes should have solved the problem for you.

@bbatsov bbatsov closed this as completed Feb 14, 2025
@jwr
Copy link
Author

jwr commented Feb 15, 2025

I can confirm that projectile 2.9.1 fixes the problem! Thank you! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants