syl20bnr / spacemacs

A community-driven Emacs distribution - The best editor is neither Emacs nor Vim, it's Emacs *and* Vim!
http://spacemacs.org
GNU General Public License v3.0
23.67k stars 4.89k forks source link

Error at init time after updating which-key package #14865

Closed bcc32 closed 3 years ago

bcc32 commented 3 years ago

Description :octocat:

Errors at init after updating which-key past a recent commit, https://github.com/justbur/emacs-which-key/commit/a55b90844c837e157c289ad4b10f5f2e3a4d53ff

I don't know whether this is a bug in which-key or whether Spacemacs is using a private interface that changed, so I reported it here. Happy to open an issue in which-key instead if it turns out the change there was broken or backward-incompatible.

Reproduction guide :beetle:

Observed behaviour: :eyes: :broken_heart: Lots of errors at init:

Error (use-package): auto-yasnippet/:init: Key sequence i S c starts with non-prefix key i S
Error (use-package): command-log-mode/:init: Key sequence a t l l starts with non-prefix key a t l
Error (use-package): counsel-spotify/:init: Key sequence a m s s T starts with non-prefix key a m s s
Error (use-package): emr/:config: Key sequence r d l starts with non-prefix key r d
Error (use-package): js-doc/:init: Key sequence r d b starts with non-prefix key r d
Error (use-package): js2-refactor/:init: Key sequence x m j starts with non-prefix key x m
Error (use-package): keycast/:init: Key sequence a t l k starts with non-prefix key a t l
Error (use-package): org/:init: Key sequence a o f i starts with non-prefix key a o f
Error (use-package): org-brain/:init: Key sequence B a c starts with non-prefix key B a
Error (use-package): org-download/:init: Key sequence i D y starts with non-prefix key i D
Error (use-package): magit/:config: replacement is neither a cons cell or a string
Warning (initialization): An error occurred while loading ‘/Users/aaron/.emacs.d/init.el’:

Also, layers are not properly initialized, so emacs just ends up being thoroughly broken.

Expected behaviour: :heart: :smile: No errors at init time.

System Info :computer:

Backtrace :paw_prints:

Debugger entered--Lisp error: (error "Key sequence x r e starts with non-prefix key x r")
  define-key((keymap (120 keymap (114 "regular expressions" . 1)) (104 keymap (107 . which-key-show-top-level)) (122 keymap (46 . spacemacs/fold-transient-state/body)) (78 keymap (71 . spacemacs/scroll-transient-state/evil-goto-line) (103 . spacemacs/scroll-transient-state/evil-goto-first-line) (62 . spacemacs/scroll-transient-state/evil-goto-line) (60 . spacemacs/scroll-transient-state/evil-goto-first-line) (98 . spacemacs/scroll-transient-state/evil-scroll-page-up) (102 . spacemacs/scroll-transient-state/evil-scroll-page-down) (76 . spacemacs/scroll-transient-state/evil-scroll-right) (72 . spacemacs/scroll-transient-state/evil-scroll-left) (75 . spacemacs/scroll-transient-state/evil-scroll-up) (74 . spacemacs/scroll-transient-state/evil-scroll-down) (117 . spacemacs/scroll-transient-state/evil-scroll-up) (100 . spacemacs/scroll-transient-state/evil-scroll-down) (108 . spacemacs/scroll-transient-state/evil-scroll-column-right) (104 . spacemacs/scroll-transient-state/evil-scroll-column-left) (107 . spacemacs/scroll-transient-state/evil-scroll-line-up) (106 . spacemacs/scroll-transient-state/evil-scroll-line-down)) (115 keymap (99 . spacemacs/evil-search-clear-highlight)) (114 keymap (101 . spacemacs/ivy-evil-registers)) (84 keymap (4 . spacemacs/toggle-version-control-margin-globally) (100 . spacemacs/toggle-version-control-margin)) (116 keymap (69 keymap (104 . spacemacs/toggle-hybrid-mode) (101 . spacemacs/toggle-holy-mode)) (107 keymap (116 . spacemacs/toggle-which-key-top-level) (77 . spacemacs/toggle-which-key-full-major-mode-map) (109 . spacemacs/toggle-which-key-major-mode-map) (107 . spacemacs/toggle-which-key-toggle-persistent)) (75 . spacemacs/toggle-which-key) (97 . spacemacs/toggle-auto-completion))) "xre" ("elisp" . 2))
  which-key-add-keymap-based-replacements((keymap (120 keymap (114 "regular expressions" . 1)) (104 keymap (107 . which-key-show-top-level)) (122 keymap (46 . spacemacs/fold-transient-state/body)) (78 keymap (71 . spacemacs/scroll-transient-state/evil-goto-line) (103 . spacemacs/scroll-transient-state/evil-goto-first-line) (62 . spacemacs/scroll-transient-state/evil-goto-line) (60 . spacemacs/scroll-transient-state/evil-goto-first-line) (98 . spacemacs/scroll-transient-state/evil-scroll-page-up) (102 . spacemacs/scroll-transient-state/evil-scroll-page-down) (76 . spacemacs/scroll-transient-state/evil-scroll-right) (72 . spacemacs/scroll-transient-state/evil-scroll-left) (75 . spacemacs/scroll-transient-state/evil-scroll-up) (74 . spacemacs/scroll-transient-state/evil-scroll-down) (117 . spacemacs/scroll-transient-state/evil-scroll-up) (100 . spacemacs/scroll-transient-state/evil-scroll-down) (108 . spacemacs/scroll-transient-state/evil-scroll-column-right) (104 . spacemacs/scroll-transient-state/evil-scroll-column-left) (107 . spacemacs/scroll-transient-state/evil-scroll-line-up) (106 . spacemacs/scroll-transient-state/evil-scroll-line-down)) (115 keymap (99 . spacemacs/evil-search-clear-highlight)) (114 keymap (101 . spacemacs/ivy-evil-registers)) (84 keymap (4 . spacemacs/toggle-version-control-margin-globally) (100 . spacemacs/toggle-version-control-margin)) (116 keymap (69 keymap (104 . spacemacs/toggle-hybrid-mode) (101 . spacemacs/toggle-holy-mode)) (107 keymap (116 . spacemacs/toggle-which-key-top-level) (77 . spacemacs/toggle-which-key-full-major-mode-map) (109 . spacemacs/toggle-which-key-major-mode-map) (107 . spacemacs/toggle-which-key-toggle-persistent)) (75 . spacemacs/toggle-which-key) (97 . spacemacs/toggle-auto-completion))) "xre" "elisp")
  spacemacs/declare-prefix("xre" "elisp")
  spacemacs-editing/post-init-pcre2el()
  funcall(spacemacs-editing/post-init-pcre2el)
  (condition-case err (funcall (intern (format "%S/post-init-%S" layer pkg-name))) ((debug quote error) (configuration-layer//error (concat "\nAn error occurred while post-configuring %S " "in layer %S (error: %s)\n") pkg-name layer err)))
  (if (not (configuration-layer//package-enabled-p pkg layer)) (spacemacs-buffer/message (format "%S -> ignored post-init (%S)..." pkg-name layer)) (spacemacs-buffer/message (format "%S -> post-init (%S)..." pkg-name layer)) (condition-case err (funcall (intern (format "%S/post-init-%S" layer pkg-name))) ((debug quote error) (configuration-layer//error (concat "\nAn error occurred while post-configuring %S " "in layer %S (error: %s)\n") pkg-name layer err))))
  (progn (if (not (configuration-layer//package-enabled-p pkg layer)) (spacemacs-buffer/message (format "%S -> ignored post-init (%S)..." pkg-name layer)) (spacemacs-buffer/message (format "%S -> post-init (%S)..." pkg-name layer)) (condition-case err (funcall (intern (format "%S/post-init-%S" layer pkg-name))) ((debug quote error) (configuration-layer//error (concat "\nAn error occurred while post-configuring %S " "in layer %S (error: %s)\n") pkg-name layer err)))))
  (if (configuration-layer/layer-used-p layer) (progn (if (not (configuration-layer//package-enabled-p pkg layer)) (spacemacs-buffer/message (format "%S -> ignored post-init (%S)..." pkg-name layer)) (spacemacs-buffer/message (format "%S -> post-init (%S)..." pkg-name layer)) (condition-case err (funcall (intern (format "%S/post-init-%S" layer pkg-name))) ((debug quote error) (configuration-layer//error (concat "\nAn error occurred while post-configuring %S " "in layer %S (error: %s)\n") pkg-name layer err))))))
  (lambda (layer) (if (configuration-layer/layer-used-p layer) (progn (if (not (configuration-layer//package-enabled-p pkg layer)) (spacemacs-buffer/message (format "%S -> ignored post-init (%S)..." pkg-name layer)) (spacemacs-buffer/message (format "%S -> post-init (%S)..." pkg-name layer)) (condition-case err (funcall (intern ...)) ((debug quote error) (configuration-layer//error ... pkg-name layer err)))))))(spacemacs-editing)
  mapc((lambda (layer) (if (configuration-layer/layer-used-p layer) (progn (if (not (configuration-layer//package-enabled-p pkg layer)) (spacemacs-buffer/message (format "%S -> ignored post-init (%S)..." pkg-name layer)) (spacemacs-buffer/message (format "%S -> post-init (%S)..." pkg-name layer)) (condition-case err (funcall (intern ...)) ((debug quote error) (configuration-layer//error ... pkg-name layer err))))))) (spacemacs-editing))
  (let* ((pkg-name (eieio-oref pkg ':name)) (owner (car (eieio-oref pkg ':owners)))) (mapc #'(lambda (layer) (if (configuration-layer/layer-used-p layer) (progn (if (not ...) (spacemacs-buffer/message ...) (spacemacs-buffer/message ...) (condition-case err ... ...))))) (eieio-oref pkg ':post-layers)))
  configuration-layer//post-configure-package(#<cfgl-package cfgl-package-4d8969c0>)
  mapc(configuration-layer//post-configure-package (#<cfgl-package cfgl-package-4d896554> #<cfgl-package cfgl-package-4d896762> #<cfgl-package cfgl-package-4d90ca64> #<cfgl-package cfgl-package-4d896bdc> #<cfgl-package cfgl-package-4d8a33b2> #<cfgl-package cfgl-package-4d8969c0>))
  (let (packages-to-configure) (let ((--dolist-tail-- packages) pkg-name) (while --dolist-tail-- (setq pkg-name (car --dolist-tail--)) (let ((pkg (configuration-layer/get-package pkg-name))) (cond ((eieio-oref pkg ':lazy-install) (spacemacs-buffer/message (format "%S ignored since it can be lazily installed." pkg-name))) ((and (eieio-oref pkg ...) (not ...)) (spacemacs-buffer/message (format "%S ignored since it has been excluded." pkg-name))) ((null (eieio-oref pkg ...)) (spacemacs-buffer/message (format "%S ignored since it has no owner layer." pkg-name))) ((not (configuration-layer//package-reqs-used-p pkg)) (spacemacs-buffer/message (format ... pkg-name))) ((not (cfgl-package-enabled-p pkg)) (spacemacs-buffer/message (format "%S is disabled." pkg-name))) (t (let (...) (if dir ...)) (if (memq ... ...) nil (configuration-layer//activate-package pkg-name)) (cond (... ...) (t ... ...))))) (setq --dolist-tail-- (cdr --dolist-tail--)))) (setq packages-to-configure (reverse packages-to-configure)) (mapc 'configuration-layer//configure-package packages-to-configure) (mapc 'configuration-layer//post-configure-package packages-to-configure))
  configuration-layer//configure-packages-2((dotenv-mode evil-evilified-state font-lock+ holy-mode hybrid-mode pcre2el))
  configuration-layer//configure-packages((abbrev ac-ispell ace-link ace-window add-node-modules-path aggressive-indent ahk-mode all-the-icons anaconda-mode ansi-colors archive-mode async auto-compile auto-complete auto-dictionary auto-highlight-symbol auto-yasnippet avy base16-theme bcc32-org bind-key bind-map blacken bookmark browse-at-remote buffer-menu bundler cc-mode centered-cursor-mode chruby clang-format clean-aindent-mode column-enforce-mode comint command-log-mode company company-anaconda company-box company-c-headers company-nixos-options company-plsense company-quickhelp company-rtags company-shell company-statistics company-web company-ycmd compile conf-mode counsel ...))
  configuration-layer//load()
  (cond (changed-since-last-dump-p (configuration-layer//load) (if (spacemacs/emacs-with-pdumper-set-p) (progn (configuration-layer/message "Layer list has changed since last dump.") (configuration-layer//dump-emacs)))) (spacemacs-force-dump (configuration-layer//load) (if (spacemacs/emacs-with-pdumper-set-p) (progn (configuration-layer/message (concat "--force-dump passed on the command line or configu..." "been reloaded, forcing a redump.")) (configuration-layer//dump-emacs)))) ((spacemacs-is-dumping-p) (configuration-layer//load)) ((and (spacemacs/emacs-with-pdumper-set-p) (spacemacs-run-from-dump-p)) (configuration-layer/message "Running from a dumped file. Skipping the loading p...")) (t (configuration-layer//load) (if (spacemacs/emacs-with-pdumper-set-p) (progn (configuration-layer/message (concat "Layer list has not changed since last time. " "Skipping dumping process!"))))))
  configuration-layer/load()
  (let ((file-name-handler-alist nil)) (require 'core-spacemacs) (spacemacs/dump-restore-load-path) (configuration-layer/load-lock-file) (spacemacs/init) (configuration-layer/stable-elpa-init) (configuration-layer/load) (spacemacs-buffer/display-startup-note) (spacemacs/setup-startup-hook) (spacemacs/dump-eval-delayed-functions) (if (and dotspacemacs-enable-server (not (spacemacs-is-dumping-p))) (progn (require 'server) (if dotspacemacs-server-socket-dir (progn (setq server-socket-dir dotspacemacs-server-socket-dir))) (if (server-running-p) nil (message "Starting a server...") (server-start)))))
  (if (not (version<= spacemacs-emacs-min-version emacs-version)) (error (concat "Your version of Emacs (%s) is too old. " "Spacemacs requires Emacs version %s or above.") emacs-version spacemacs-emacs-min-version) (let ((file-name-handler-alist nil)) (require 'core-spacemacs) (spacemacs/dump-restore-load-path) (configuration-layer/load-lock-file) (spacemacs/init) (configuration-layer/stable-elpa-init) (configuration-layer/load) (spacemacs-buffer/display-startup-note) (spacemacs/setup-startup-hook) (spacemacs/dump-eval-delayed-functions) (if (and dotspacemacs-enable-server (not (spacemacs-is-dumping-p))) (progn (require 'server) (if dotspacemacs-server-socket-dir (progn (setq server-socket-dir dotspacemacs-server-socket-dir))) (if (server-running-p) nil (message "Starting a server...") (server-start))))))
  eval-buffer(#<buffer  *load*> nil "/Users/aaron/.emacs.d/init.el" nil t)  ; Reading at buffer position 3159
  load-with-code-conversion("/Users/aaron/.emacs.d/init.el" "/Users/aaron/.emacs.d/init.el" t t)
  load("/Users/aaron/.emacs.d/init" noerror nomessage)
  startup--load-user-init-file(#f(compiled-function () #<bytecode 0x4e0a874f>) #f(compiled-function () #<bytecode 0x4e0a8765>) t)
  command-line()
  normal-top-level()
bcc32 commented 3 years ago

Somewhat annoyingly, it is not possible to rollback packages through Spacemacs because Spacemacs fails to init. If this happens to you, the following workaround may help (this is just the rollback procedure, but done manually):

  1. Delete the which-key directory in ~/.emacs.d/elpa/$version/develop/
  2. Find the most recent snapshot of which-key before 2021-06-21 in ~/.emacs.d/.cache/.rollback/$version/develop/$date/ and copy it into the directory in the previous step.
  3. Restart emacs. It should no longer fail to initialize.
lebensterben commented 3 years ago

Looks like an upstream bug.

lebensterben commented 3 years ago

From the debug traceback you can see that we haven't directly called any function that is changed in this commit.

So this looks like an internal error of which-key.

TakaakiFuruse commented 3 years ago

I am having the same issue and got the same kind of message.

Error (use-package): auto-yasnippet/:init: Key sequence i S c starts with non-prefix key i S
Error (use-package): emr/:config: Key sequence r d l starts with non-prefix key r d
Error (use-package): github-clone/:init: Key sequence g h c c starts with non-prefix key g h c
Error (use-package): github-search/:init: Key sequence g h c / starts with non-prefix key g h c
Error (use-package): js-doc/:init: Key sequence r d b starts with non-prefix key r d
Error (use-package): js2-refactor/:init: Key sequence x m j starts with non-prefix key x m
Error (use-package): rainbow-identifiers/:init: Key sequence C i s starts with non-prefix key C i
Warning (initialization): An error occurred while loading ‘/home/xxx/.emacs.d/init.el’:

error: Key sequence K r s starts with non-prefix key K r

I just downloaded latest which-key from here and replaced which-key.el in elpa directory.

Looks it's working. The problem was which-key.

Thank you @bcc32

robbyoconnor commented 3 years ago

I grabbed this one: https://raw.githubusercontent.com/justbur/emacs-which-key/v3.5.2/which-key.el

robbyoconnor commented 3 years ago

@justbur sorry for tagging you, should I file an issue upstream?

justbur commented 3 years ago

@robbyoconnor if you can isolate the issue, yes.

justbur commented 3 years ago

Can someone try https://github.com/justbur/emacs-which-key/commit/6290c9e21710c3ebbcdec795c916994682e07c94 ?

tshu-w commented 3 years ago

@justbur Sorry for maybe not relevant, but after update to latest which-key(commit 28f386cc4af8c0fe21269bb587a5bb229ba3834e version: 20210622.334) general cannot work with which-key, Is there any breaking change? before:

Screen Shot 2021-06-22 at 21 06 57

after:

Screen Shot 2021-06-22 at 21 06 21
justbur commented 3 years ago

@tshu-w I use general and it's working fine for me. There might be an issue somewhere in how general defines replacements. I would need more information to determine what the issue is though.

tshu-w commented 3 years ago

@tshu-w I use general and it's working fine for me. There might be an issue somewhere in how general defines replacements. I would need more information to determine what the issue is though.

OK, I will create an issue tomorrow. now 4c27fc0c565cdda58270dae4024ad03a0017de43 works.

dschrempf commented 3 years ago

4c27fc0c565cdda58270dae4024ad03a0017de43 doesn't work for me. I had to roll back to an earlier version as described above.

duianto commented 3 years ago

It's caused by these lines on startup: https://github.com/syl20bnr/spacemacs/blob/443311c8f1d7c6ebbe1d10be576a4edc47e03a5a/layers/%2Bspacemacs/spacemacs-defaults/funcs.el#L136-L142

And when the git layer is enabled and a magit buffer is opened, then a warnings buffer opens with the message:

Error (use-package): magit/:config: replacement is neither a cons cell or a string

It's caused by these lines: https://github.com/syl20bnr/spacemacs/blob/443311c8f1d7c6ebbe1d10be576a4edc47e03a5a/layers/%2Bsource-control/git/packages.el#L273-L279

Source: This was found by logging the which-key-add-keymap-based-replacements parameters in which-key.el

(message "start of WHICH-KEY-ADD-KEYMAP-BASED-REPLACEMENTS")
;; (message "keymap: %s" keymap)
(message "key: %s" key)
(message "replacement: %s" replacement)
(message "more: %s" more)

which showed:

key: <normal-state> g r
replacement: nil
more: (<visual-state> g r nil)

before the error:

user-error: replacement is neither a cons cell or a string

chrispickard commented 3 years ago

according to the upstream issue, this is an issue with spacemacs' usage of that function

duianto commented 3 years ago

The previous fix doesn't seem to be needed anymore: Fix which-key entries: gr and gs in dired and magit https://github.com/syl20bnr/spacemacs/commit/ec57b21a924d88fa0f7e1d747f091c349cca0170

The expected which-key entries appear when the fix is reverted.

A PR has been opened with a possible fix by reverting the previous fix: Revert "Fix which-key entries: gr and gs in dired and magit" https://github.com/syl20bnr/spacemacs/pull/14869

Update:

The PR has been merged.

chrispickard commented 3 years ago

that took care of the issue for me, I think this issue can be closed. Thanks for the work!

lebensterben commented 3 years ago

@bcc32

Please verify if the bug is fixed.

bcc32 commented 3 years ago

Updating Spacemacs and then packages seems to have worked for me. I see no error messages at startup. Thanks all