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

Magit fails to start with 'Selecting delete buffer' #535

Closed
yasuhirokimura opened this issue Jan 16, 2023 · 15 comments
Closed

Magit fails to start with 'Selecting delete buffer' #535

yasuhirokimura opened this issue Jan 16, 2023 · 15 comments

Comments

@yasuhirokimura
Copy link

yasuhirokimura commented Jan 16, 2023

Conditions

  • OS: 64bit Windows 10 22H2
  • Build environment: MSYS2 MinGW x64 console
  • Emacs: bb679244152 of master
  • Forge: efc5d46 of main
  • Magit: 59833692 of main
  • closql: 1aba696 of main
  • compat: 45ae45a of master
  • dash.el: 3df46d7 of master
  • emacsql: 6b2e65b of main
  • emacs-sqlite3-api: ad6dc36 off master
  • ghub: 1ff2574 of main
  • markdown-mode: 6024f2d of master
  • pg-el: f91d546 of main
  • transient: 239be53 of main
  • treepy.el: 7c4a0d2 of master
  • with-editor: 84ba06e of main
  • yaml.el: 73fde9d of master

Steps to reproduce the issue

  1. Clone the repostory of Forge with git clone https://github.com/magit/forge.git.
  2. Start Emacs with emacs -q --no-site-file.
  3. Switch to 'scratch' buffer.
  4. Type (require 'magit) and evaluate it with C-j.
  5. Type (require 'forge) and evaluate it with C-j.
  6. Invoke Magit with M-x magit and select the repositoy cloned at step 1.

Expected behavior

Magit successfuly starts and buffer named magit: forge is created.

What really happens

Magit fails to start with Selection deleted buffer.

Backtrace

Debugger entered--Lisp error: (error "Selecting deleted buffer")
  #f(compiled-function (connection) "Return true if the end of the buffer has a properly-formatted prompt." #<bytecode -0xa843717a7a3f655>)(#<forge-database forge-database-a01c252608>)
  apply(#f(compiled-function (connection) "Return true if the end of the buffer has a properly-formatted prompt." #<bytecode -0xa843717a7a3f655>) #<forge-database forge-database-a01c252608> nil)
  emacsql-waiting-p(#<forge-database forge-database-a01c252608>)
  #f(compiled-function (connection &optional timeout) "Block until CONNECTION is waiting for further input." #<bytecode 0x2f34ace592142e5>)(#<forge-database forge-database-a01c252608>)
  apply(#f(compiled-function (connection &optional timeout) "Block until CONNECTION is waiting for further input." #<bytecode 0x2f34ace592142e5>) #<forge-database forge-database-a01c252608> nil)
  emacsql-wait(#<forge-database forge-database-a01c252608>)
  #f(compiled-function (connection &rest rest) #<bytecode -0x2aaa6220f3798ab>)(#<forge-database forge-database-a01c252608> (:file "c:/Users/yasu/.emacs.d/forge-database.sqlite"))
  apply(#f(compiled-function (connection &rest rest) #<bytecode -0x2aaa6220f3798ab>) (#<forge-database forge-database-a01c252608> (:file "c:/Users/yasu/.emacs.d/forge-database.sqlite")))
  #f(compiled-function (&rest args) #<bytecode 0x1d0de56ae1e8df21>)(#<forge-database forge-database-a01c252608> (:file "c:/Users/yasu/.emacs.d/forge-database.sqlite"))
  apply(#f(compiled-function (&rest args) #<bytecode 0x1d0de56ae1e8df21>) #<forge-database forge-database-a01c252608> (:file "c:/Users/yasu/.emacs.d/forge-database.sqlite"))
  initialize-instance(#<forge-database forge-database-a01c252608> (:file "c:/Users/yasu/.emacs.d/forge-database.sqlite"))
  #f(compiled-function (class &rest slots) "Default constructor for CLASS `eieio-default-superclass'.\nSLOTS are the initialization slots used by `initialize-instance'.\nThis static method is called when an object is constructed.\nIt allocates the vector used to represent an EIEIO object, and then\ncalls `initialize-instance' on that object." #<bytecode -0xcc58ba9dda1661b>)(forge-database :file "c:/Users/yasu/.emacs.d/forge-database.sqlite")
  apply(#f(compiled-function (class &rest slots) "Default constructor for CLASS `eieio-default-superclass'.\nSLOTS are the initialization slots used by `initialize-instance'.\nThis static method is called when an object is constructed.\nIt allocates the vector used to represent an EIEIO object, and then\ncalls `initialize-instance' on that object." #<bytecode -0xcc58ba9dda1661b>) forge-database (:file "c:/Users/yasu/.emacs.d/forge-database.sqlite"))
  make-instance(forge-database :file "c:/Users/yasu/.emacs.d/forge-database.sqlite")
  #f(compiled-function (class &optional variable file debug) #<bytecode 0xfcc88fd70425bc5>)(forge-database forge--db-connection "c:/Users/yasu/.emacs.d/forge-database.sqlite" t)
  apply(#f(compiled-function (class &optional variable file debug) #<bytecode 0xfcc88fd70425bc5>) forge-database (forge--db-connection "c:/Users/yasu/.emacs.d/forge-database.sqlite" t))
  closql-db(forge-database forge--db-connection "c:/Users/yasu/.emacs.d/forge-database.sqlite" t)
  forge-db()
  forge-sql([:select * :from repository :where (and (= forge $s1) (= owner $s2) (= name $s3))] "github.com" "magit" "forge")
  #f(compiled-function (&rest rest) "((host owner name) &optional remote demand)\n\nReturn the repository identified by HOST, OWNER and NAME." #<bytecode -0x3a851fceec0905a>)(("github.com" "magit" "forge") "origin" full)
  apply(#f(compiled-function (&rest rest) "((host owner name) &optional remote demand)\n\nReturn the repository identified by HOST, OWNER and NAME." #<bytecode -0x3a851fceec0905a>) ("github.com" "magit" "forge") ("origin" full))
  forge-get-repository(("github.com" "magit" "forge") "origin" full)
  #f(compiled-function (url &optional remote demand) "Return the repository at URL." #<bytecode -0x1e39f9bc9880dc9e>)("https://github.com/magit/forge.git" "origin" full)
  apply(#f(compiled-function (url &optional remote demand) "Return the repository at URL." #<bytecode -0x1e39f9bc9880dc9e>) "https://github.com/magit/forge.git" ("origin" full))
  forge-get-repository("https://github.com/magit/forge.git" "origin" full)
  #f(compiled-function (demand &optional remote) "Return the current forge repository.\n\nIf the `forge-buffer-repository' is non-nil, then return that.\nOtherwise if `forge-buffer-topic' is non-nil, then return the\nrepository for that.  Finally if both variables are nil, then\nreturn the forge repository corresponding to the current Git\nrepository, if any." #<bytecode -0x1b3bfa001a860e30>)(full)
  apply(#f(compiled-function (demand &optional remote) "Return the current forge repository.\n\nIf the `forge-buffer-repository' is non-nil, then return that.\nOtherwise if `forge-buffer-topic' is non-nil, then return the\nrepository for that.  Finally if both variables are nil, then\nreturn the forge repository corresponding to the current Git\nrepository, if any." #<bytecode -0x1b3bfa001a860e30>) full nil)
  forge-get-repository(full)
  forge-bug-reference-setup()
  run-hooks(change-major-mode-after-body-hook special-mode-hook magit-section-mode-hook magit-mode-hook magit-status-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook special-mode-hook magit-section-mode-hook magit-mode-hook magit-status-mode-hook))
  run-mode-hooks(magit-status-mode-hook)
  magit-status-mode()
  magit-setup-buffer-internal(magit-status-mode nil ((magit-buffer-diff-args ("--no-ext-diff")) (magit-buffer-diff-files nil) (magit-buffer-log-args ("-n256" "--decorate")) (magit-buffer-log-files nil)))
  magit-status-setup-buffer("c:/Users/yasu/Temp/forge/")
  magit("~/Temp/forge/" ((6 . 10) (("c:/Users/yasu/Temp/forge/" "remote" "get-url" "origin") . "https://github.com/magit/forge.git") (("c:/Users/yasu/Temp/forge/" . config) . #<hash-table equal 29/65 0xa01c17ac85>) (("c:/Users/yasu/Temp/forge/" . magit-toplevel) . "c:/Users/yasu/Temp/forge/") (("~/Temp/forge/" . magit-toplevel) . "c:/Users/yasu/Temp/forge/") (("c:/Users/yasu/Temp/forge/" "rev-parse" "--show-toplevel") . "/c/Users/yasu/Temp/forge") (("~/" "config" "--get-color" "" "reset") . "\33[m") (("~/" . magit-toplevel)) (("c:/Users/yasu/" "rev-parse" "--git-dir")) (("c:/Users/yasu/" "rev-parse" "--show-toplevel"))))
  funcall-interactively(magit "~/Temp/forge/" ((6 . 10) (("c:/Users/yasu/Temp/forge/" "remote" "get-url" "origin") . "https://github.com/magit/forge.git") (("c:/Users/yasu/Temp/forge/" . config) . #<hash-table equal 29/65 0xa01c17ac85>) (("c:/Users/yasu/Temp/forge/" . magit-toplevel) . "c:/Users/yasu/Temp/forge/") (("~/Temp/forge/" . magit-toplevel) . "c:/Users/yasu/Temp/forge/") (("c:/Users/yasu/Temp/forge/" "rev-parse" "--show-toplevel") . "/c/Users/yasu/Temp/forge") (("~/" "config" "--get-color" "" "reset") . "\33[m") (("~/" . magit-toplevel)) (("c:/Users/yasu/" "rev-parse" "--git-dir")) (("c:/Users/yasu/" "rev-parse" "--show-toplevel"))))
  call-interactively(magit record nil)
  command-execute(magit record)
  execute-extended-command(nil "magit" "magit")
  funcall-interactively(execute-extended-command nil "magit" "magit")
  call-interactively(execute-extended-command nil nil)
  command-execute(execute-extended-command)

Other things I know about this issue

  1. The issue doesn't happen if step 5 of steps to reproduce the issue is skipped. That's why I report it here rather than issue tracker of Magit.
  2. The issue appeared after I updated Emacs to latest commit of master branch. So I tried bisect and according to the result, the issue happens with following commit and later.
commit 4f0459aaf75
Merge: 99120491730 861556c1339
Author:     Stefan Monnier <monnier@iro.umontreal.ca>
AuthorDate: Sat Jan 14 09:10:45 2023 -0500
Commit:     Stefan Monnier <monnier@iro.umontreal.ca>
CommitDate: Sat Jan 14 09:10:45 2023 -0500

    Merge from origin/emacs-29

    861556c1339 Fix minibuffer-completion tests
    c0578edc8fc ; * doc/misc/eglot.texi (Troubleshooting Eglot): Fix typo...
    c6bbf9cc270 Add c-ts-mode tests
    a760364f5f3 Fix c-ts-mode--fill-paragraph
    2a2b1d09ac7 Fix minor issues with 'pp' and related commands
    dfb38fb2ee6 ; Improve documentation of tree-sitter node comparison
    e8a89a18b69 ; Fix non-tree-sitter builds
    f27a330b99e ; Fix typo in ert-with-temp-file
    956889d8ff1 Equal now recognizes tree-sitter nodes (bug#60659)
    8f446c2d397 Fix c-ts-mode comment indentation (bug#60270)
    083badc9c12 * lisp/subr.el (while-let): Use if-let, not if-let* (bug#...
    9ecebcdded1 * lisp/simple.el (next-completion): Handle first completi...
    cfd2b3504ab Fix encoding with 'utf-8-auto'
    53b47df8229 Report cursor correctly on PGTK when there is a margin

    # Conflicts:
    #       etc/NEWS
@yasuhirokimura
Copy link
Author

The issue also happens on FreeBSD with following conditions.

  • OS: FreeBSD 13.1-RELEASE amd64
  • Emacs: 16579f6ed77 of master
  • Forge: 6ff776a of main
  • Magit: a103d11a of main
  • closql: v1.2.1
  • compat: 29.1.1.1
  • dash.el: 2.19.1
  • emacsql: 3.1.1
  • ghub: 142b0db of main
  • markdown-mode: v2.5
  • pg-el: v0.20
  • transient: c6cf2f2 of main
  • treepy.el: 0.1.2
  • with-editor: 4da1097 of main
  • yaml.el: v0.5.1

@diegov
Copy link

diegov commented Jan 16, 2023

I bisected the emacs-29 branch, the first bad commit is this:

commit cfd2b3504ab5de6eb5f3c7a0784cb447883e1326 (HEAD, refs/bisect/bad)
Author: Eli Zaretskii <eliz@gnu.org>
Date:   Thu Jan 12 16:36:35 2023 +0200

    Fix encoding with 'utf-8-auto'

    * src/coding.c (encode_coding_utf_8): Fix encoding with
    'utf-8-auto': it should produce BOM, per the documentation of
    the :bom attribute.  (Bug#60750)

    * lisp/international/mule.el (define-coding-system): Doc fix.

    * test/src/coding-tests.el (coding-tests): Use
    'with-coding-priority' instead of 'prefer-coding-system', as the
    latter has global persistent effect and affects further tests.

The "selecting deleted buffer" error does not actually happen on that commit, magit is able to show the status buffer, but the failure to initialize the forge DB (which seems to be the root cause) does.

@tsdh
Copy link
Contributor

tsdh commented Jan 17, 2023

Bug report on the emacs side: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=60872

tarsius added a commit to magit/emacsql that referenced this issue Jan 17, 2023
This fixes an issue that was merely triggered by a change in Emacs
[1].  [2: 127bb98] started binding `coding-system-for-write' and
`coding-system-for-read' to `utf-8-auto'.  As Eli points out at [3]
`utf-8-auto' was probably a mistake and `utf-8' should have been
used instead.

1: emacsmirror/emacs@cfd2b3504ab5de6eb5

2: 2014-02-02 127bb98
   Set coding system to utf-8-auto for sqlite.

3: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=60872#11.

   > Setting coding-system-for-write to utf-8-auto makes no sense;
   > that coding-system's _only_ raison d'être is for using in
   > coding-system-for-read, i.e. when decoding stuff that may or
   > may not start with a BOM.

Since EmacSQL is not a general-purpose database but instead stores
data encoded by Emacs for later retrieval by Emacs only, we do not
have to with the unlikely appearance of a BOM, so we can use `utf-8'
instead of `utf-8-auto' for writes *and* reads.

Re #104, #106, magit/forge#533, magit/forge#535, bug#60872.
@tsdh
Copy link
Contributor

tsdh commented Jan 18, 2023

@tarsius Hi Jonas, I can confirm that forge/emacsql works again after that change. Thanks a lot!

@tarsius
Copy link
Member

tarsius commented Jan 18, 2023

Thanks for confirming that.

I've also just added a commit to prevent the secondary error Selecting deleted buffer reported here with, magit/emacsql@2e6056d. magit/emacsql@9388503 should also help finding the cause of similar issues in the future.

@aiguofer
Copy link

aiguofer commented Jul 4, 2023

Hi, I keep running into this issue. I'm on Emacs 29 using emacs-pus homebrew on MacOS (brew install emacs-plus@29 --with-native-comp --with-xwidgets). I've tried to go through all the different threads related to this to understand the problem and tried various things (update/reinstall emacs, clear out use-package build dir, update all deps, install sqlite3, change some utf-8 related settings), but I always get the error Process emacsql-sqlite not running: finished or Selecting deleted buffer when I try to start up magit with forge installed.

Any help would be greatly appreciated! I'd love to be able to use forge again. I've had it disabled for a few months now and just had some free time to mess with it, but the last few hours have been futile.

@tarsius
Copy link
Member

tarsius commented Jul 11, 2023

Do you get a backtrace if you enable debugging?
What does emacsql-sqlite-default-connection return?

@aiguofer
Copy link

It does not throw a backtrace with debugging enabled.... and is emacsql-sqlite-default-connection a function or var? I can't find either.

@tarsius
Copy link
Member

tarsius commented Jul 13, 2023

It is a function defined in emacsql-sqlite-common.el. If that library is missing, then the installed emacsql is outdated.

All libraries are now included in just one package emacsql. Uninstall all emacsql-* packages and make sure emacsql is up-to-date. The emacsql-* packages are still available from Melpa during a transitional period, see melpa/melpa@4872ef0.

@aiguofer
Copy link

Ahhh thanks! I use straight.el so I though it had updated it on its own, but when I tried to manually update the local repo I got:

❯ cd ~/.emacs.d/straight/repos/emacsql
❯ git up
Fetching origin
master  error: remote branch doesn't exist

I deleted the emacsql-* repos and now it works.

@tarsius
Copy link
Member

tarsius commented Jul 13, 2023

So straight did not recover from the renaming of the default branch? Many Straight users might run into this issue if that is the case. ☹️

@aiguofer
Copy link

It's kinda weird because when I run straight-pull-all it generally tells me about branch changes or remote changes, so it could be something weird going on with my setup. Hopefully if other straight users run into this they find this!

@imu96
Copy link

imu96 commented Sep 3, 2023

Ahhh thanks! I use straight.el so I though it had updated it on its own, but when I tried to manually update the local repo I got:

❯ cd ~/.emacs.d/straight/repos/emacsql
❯ git up
Fetching origin
master  error: remote branch doesn't exist

I deleted the emacsql-* repos and now it works.

When you say you deleted the emacsql-* repos what does that mean exactly? Like you deleted all the .el files in the emacsql folder beginning with emacsql-*? I tried that and it didn't fix the issue for me unfortunately (I use straight as well).

@aiguofer
Copy link

aiguofer commented Sep 3, 2023

When you say you deleted the emacsql-* repos what does that mean exactly? Like you deleted all the .el files in the emacsql folder beginning with emacsql-*? I tried that and it didn't fix the issue for me unfortunately (I use straight as well).

I ran rm -rf ~/.emacs.d/straight/repos/emacsql*. This forces straight.el to pull all the latest repos and build them.

@imu96
Copy link

imu96 commented Sep 3, 2023

Wow it worked like a charm! Thanks so much for your help!

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

6 participants