magit / emacsql

A high-level Emacs Lisp RDBMS front-end
The Unlicense
553 stars 41 forks source link

error selecting deleted buffer #68

Closed dericbytes closed 2 years ago

dericbytes commented 3 years ago

With emacs -q I ran this

(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
(package-install 'emacsql-sqlite)

(require 'emacsql-sqlite)
(setq db (emacsql-sqlite "/media/dericbytes/Extreme 500/main-photos/photos.db"))

and got this error

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 0x19b6f9d97cd7d3ab>)(#<emacsql-sqlite-connection emacsql-sqlite-connection-158aaf093b9c>)
  apply(#f(compiled-function (connection) "Return true if the end of the buffer has a properly-formatted prompt." #<bytecode 0x19b6f9d97cd7d3ab>) #<emacsql-sqlite-connection emacsql-sqlite-connection-158aaf093b9c> nil)
  emacsql-waiting-p(#<emacsql-sqlite-connection emacsql-sqlite-connection-158aaf093b9c>)
  #f(compiled-function (connection &optional timeout) "Block until CONNECTION is waiting for further input." #<bytecode -0x1bb371ae8faf3ead>)(#<emacsql-sqlite-connection emacsql-sqlite-connection-158aaf093b9c>)
  apply(#f(compiled-function (connection &optional timeout) "Block until CONNECTION is waiting for further input." #<bytecode -0x1bb371ae8faf3ead>) #<emacsql-sqlite-connection emacsql-sqlite-connection-158aaf093b9c> nil)
  emacsql-wait(#<emacsql-sqlite-connection emacsql-sqlite-connection-158aaf093b9c>)
  #f(compiled-function (#<emacsql-sqlite-connection emacsql-sqlite-connection-158aaf093b9c> (:file "/media/dericbytes/Extreme 500/main-photos/photos.d..."))
  apply(#f(compiled-function 
  #f(compiled-function (&rest args) #<bytecode -0xaa0c6eb95f9b1b9>)(#<emacsql-sqlite-connection emacsql-sqlite-connection-158aaf093b9c> (:file "/media/dericbytes/Extreme 500/main-photos/photos.d..."))
  apply(#f(compiled-function (&rest args) #<bytecode -0xaa0c6eb95f9b1b9>) #<emacsql-sqlite-connection emacsql-sqlite-connection-158aaf093b9c> (:file "/media/dericbytes/Extreme 500/main-photos/photos.d..."))
  initialize-instance(#<emacsql-sqlite-connection emacsql-sqlite-connection-158aaf093b9c> (:file "/media/dericbytes/Extreme 500/main-photos/photos.d..."))
  #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 0x1e4a7807358a4b96>)(emacsql-sqlite-connection :file "/media/dericbytes/Extreme 500/main-photos/photos.d...")
  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 0x1e4a7807358a4b96>) emacsql-sqlite-connection (:file "/media/dericbytes/Extreme 500/main-photos/photos.d..."))
  make-instance(emacsql-sqlite-connection :file "/media/dericbytes/Extreme 500/main-photos/photos.d...")
  emacsql-sqlite("/media/dericbytes/Extreme 500/main-photos/photos.d...")
  (setq db (emacsql-sqlite "/media/dericbytes/Extreme 500/main-photos/photos.d..."))
  (progn (setq db (emacsql-sqlite "/media/dericbytes/Extreme 500/main-photos/photos.d...")))
  eval((progn (setq db (emacsql-sqlite "/media/dericbytes/Extreme 500/main-photos/photos.d..."))) t)
  elisp--eval-last-sexp(nil)
  eval-last-sexp(nil)
  funcall-interactively(eval-last-sexp nil)
  call-interactively(eval-last-sexp nil nil)
  command-execute(eval-last-sexp)

I had tried with straight.el previously on my normal setup and got the same message

Linux Slug 4.15.0-115-generic #116-Ubuntu SMP Wed Aug 26 14:04:49 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

GNU Emacs 28.0.50 (build 3, x86_64-pc-linux-gnu, GTK+ Version 3.22.30, cairo version 1.15.10) of 2020-10-04

dericbytes commented 3 years ago

I just noticed I should have used emacsql-sqlite3..... I ran it with that and got the same problem.

(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
;; Comment/uncomment this line to enable MELPA Stable if desired.  See `package-archive-priorities`
;; and `package-pinned-packages`. Most users will not need or want to do this.
;;(add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t)
(package-initialize)
(package-install 'emacsql-sqlite3)

(require 'emacsql-sqlite3)
(setq db (emacsql-sqlite3 "/media/dericbytes/Extreme 500/main-photos/photos.db"))
dericbytes commented 3 years ago

Solved it.

My external drive was not mounted.

gopar commented 3 years ago

I still get this error. Not sure what the problem is. I get it on both of my laptops :(

bitozoid commented 2 years ago

I was also having this error. It was happening because my system was setup with clang compiler and lld linker. Once I switched to gcc and bfd it got fixed.

These are the steps to reproduce the error:

(require 'emacsql-sqlite) (setq db (emacsql-sqlite "/tmp/test.db"))


- eval buffer with `M-x eval-buffer`

Then I got the "Selecting deleted buffer" until I switched compiler and linker.
bitozoid commented 2 years ago

Btw, remember to run

(emacsql-sqlite-compile)

once you have changed your compiler.

slackline commented 2 years ago

I've encountered this error using both org-roam and forge / ghub and am using gcc.

The debug from trying to use forge gives the following...

  emacsql-waiting-p(#<forge-database forge-database-1586be237ec0>)
  (not (emacsql-waiting-p connection))
  (and (or (null real-timeout) (< (float-time) end)) (not (emacsql-waiting-p connection)))
  (while (and (or (null real-timeout) (< (float-time) end)) (not (emacsql-waiting-p connection))) (let ((save-match-data-internal (match-data))) (unwind-protect (progn (accept-process-output (emacsql-process connection) real-timeout)) (set-match-data save-match-data-internal 'evaporate))))
  (let* ((real-timeout (or timeout emacsql-global-timeout)) (end (if real-timeout (progn (+ (float-time) real-timeout))))) (while (and (or (null real-timeout) (< (float-time) end)) (not (emacsql-waiting-p connection))) (let ((save-match-data-internal (match-data))) (unwind-protect (progn (accept-process-output (emacsql-process connection) real-timeout)) (set-match-data save-match-data-internal 'evaporate)))) (if (emacsql-waiting-p connection) nil (signal 'emacsql-timeout (list "Query timed out" real-timeout))))
  (progn (let* ((real-timeout (or timeout emacsql-global-timeout)) (end (if real-timeout (progn (+ (float-time) real-timeout))))) (while (and (or (null real-timeout) (< (float-time) end)) (not (emacsql-waiting-p connection))) (let ((save-match-data-internal (match-data))) (unwind-protect (progn (accept-process-output (emacsql-process connection) real-timeout)) (set-match-data save-match-data-internal 'evaporate)))) (if (emacsql-waiting-p connection) nil (signal 'emacsql-timeout (list "Query timed out" real-timeout)))))
  (closure (t) (connection &optional timeout) "Block until CONNECTION is waiting for further inpu..." (progn (let* ((real-timeout (or timeout emacsql-global-timeout)) (end (if real-timeout (progn ...)))) (while (and (or (null real-timeout) (< ... end)) (not (emacsql-waiting-p connection))) (let ((save-match-data-internal ...)) (unwind-protect (progn ...) (set-match-data save-match-data-internal ...)))) (if (emacsql-waiting-p connection) nil (signal 'emacsql-timeout (list "Query timed out" real-timeout))))))(#<forge-database forge-database-1586be237ec0>)
  apply((closure (t) (connection &optional timeout) "Block until CONNECTION is waiting for further inpu..." (progn (let* ((real-timeout (or timeout emacsql-global-timeout)) (end (if real-timeout (progn ...)))) (while (and (or (null real-timeout) (< ... end)) (not (emacsql-waiting-p connection))) (let ((save-match-data-internal ...)) (unwind-protect (progn ...) (set-match-data save-match-data-internal ...)))) (if (emacsql-waiting-p connection) nil (signal 'emacsql-timeout (list "Query timed out" real-timeout)))))) #<forge-database forge-database-1586be237ec0> nil)
  emacsql-wait(#<forge-database forge-database-1586be237ec0>)
  (let* ((process-connection-type nil) (coding-system-for-write 'utf-8-auto) (coding-system-for-read 'utf-8-auto) (file (slot-value connection 'file)) (buffer (generate-new-buffer " *emacsql-sqlite*")) (fullfile (if file (expand-file-name file) ":memory:")) (process (start-process "emacsql-sqlite" buffer emacsql-sqlite-executable fullfile))) (let* ((v connection)) (eieio-oset v 'process process)) (let* ((v process)) (set-process-sentinel v #'(lambda (proc _) (kill-buffer (process-buffer proc))))) (emacsql-wait connection) (emacsql connection [:pragma (= busy-timeout $s1)] (/ (* emacsql-global-timeout 1000) 2)) (emacsql-register connection))
  (progn (emacsql-sqlite-ensure-binary) (let* ((process-connection-type nil) (coding-system-for-write 'utf-8-auto) (coding-system-for-read 'utf-8-auto) (file (slot-value connection 'file)) (buffer (generate-new-buffer " *emacsql-sqlite*")) (fullfile (if file (expand-file-name file) ":memory:")) (process (start-process "emacsql-sqlite" buffer emacsql-sqlite-executable fullfile))) (let* ((v connection)) (eieio-oset v 'process process)) (let* ((v process)) (set-process-sentinel v #'(lambda (proc _) (kill-buffer (process-buffer proc))))) (emacsql-wait connection) (emacsql connection [:pragma (= busy-timeout $s1)] (/ (* emacsql-global-timeout 1000) 2)) (emacsql-register connection)))
  (progn (progn (emacsql-sqlite-ensure-binary) (let* ((process-connection-type nil) (coding-system-for-write 'utf-8-auto) (coding-system-for-read 'utf-8-auto) (file (slot-value connection 'file)) (buffer (generate-new-buffer " *emacsql-sqlite*")) (fullfile (if file (expand-file-name file) ":memory:")) (process (start-process "emacsql-sqlite" buffer emacsql-sqlite-executable fullfile))) (let* ((v connection)) (eieio-oset v 'process process)) (let* ((v process)) (set-process-sentinel v #'(lambda (proc _) (kill-buffer ...)))) (emacsql-wait connection) (emacsql connection [:pragma (= busy-timeout $s1)] (/ (* emacsql-global-timeout 1000) 2)) (emacsql-register connection))))
  (closure (t) (connection &rest _) "\n\n(fn CONNECTION &rest ##)" (progn (progn (emacsql-sqlite-ensure-binary) (let* ((process-connection-type nil) (coding-system-for-write 'utf-8-auto) (coding-system-for-read 'utf-8-auto) (file (slot-value connection ...)) (buffer (generate-new-buffer " *emacsql-sqlite*")) (fullfile (if file ... ":memory:")) (process (start-process "emacsql-sqlite" buffer emacsql-sqlite-executable fullfile))) (let* ((v connection)) (eieio-oset v 'process process)) (let* ((v process)) (set-process-sentinel v #'...)) (emacsql-wait connection) (emacsql connection [:pragma (= busy-timeout $s1)] (/ (* emacsql-global-timeout 1000) 2)) (emacsql-register connection)))))(#<forge-database forge-database-1586be237ec0> (:file "/home/neil/.config/emacs/forge-database.sqlite"))
  apply((closure (t) (connection &rest _) "\n\n(fn CONNECTION &rest ##)" (progn (progn (emacsql-sqlite-ensure-binary) (let* ((process-connection-type nil) (coding-system-for-write 'utf-8-auto) (coding-system-for-read 'utf-8-auto) (file (slot-value connection ...)) (buffer (generate-new-buffer " *emacsql-sqlite*")) (fullfile (if file ... ":memory:")) (process (start-process "emacsql-sqlite" buffer emacsql-sqlite-executable fullfile))) (let* ((v connection)) (eieio-oset v 'process process)) (let* ((v process)) (set-process-sentinel v #'...)) (emacsql-wait connection) (emacsql connection [:pragma (= busy-timeout $s1)] (/ (* emacsql-global-timeout 1000) 2)) (emacsql-register connection))))) (#<forge-database forge-database-1586be237ec0> (:file "/home/neil/.config/emacs/forge-database.sqlite")))
  #f(compiled-function (&rest args) #<bytecode 0x2fe89e6bbe0bc38>)(#<forge-database forge-database-1586be237ec0> (:file "/home/neil/.config/emacs/forge-database.sqlite"))
  apply(#f(compiled-function (&rest args) #<bytecode 0x2fe89e6bbe0bc38>) #<forge-database forge-database-1586be237ec0> (:file "/home/neil/.config/emacs/forge-database.sqlite"))
  initialize-instance(#<forge-database forge-database-1586be237ec0> (:file "/home/neil/.config/emacs/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 0x234ed3ad45a46de>)(forge-database :file "/home/neil/.config/emacs/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 0x234ed3ad45a46de>) forge-database (:file "/home/neil/.config/emacs/forge-database.sqlite"))
  make-instance(forge-database :file "/home/neil/.config/emacs/forge-database.sqlite")
  #f(compiled-function (class &optional variable file debug) #<bytecode 0x1cfd342ad782e28f>)(forge-database forge--db-connection "/home/neil/.config/emacs/forge-database.sqlite" t)
  apply(#f(compiled-function (class &optional variable file debug) #<bytecode 0x1cfd342ad782e28f>) forge-database (forge--db-connection "/home/neil/.config/emacs/forge-database.sqlite" t))
  closql-db(forge-database forge--db-connection "/home/neil/.config/emacs/forge-database.sqlite" t)
  forge-db()
  forge-sql([:select * :from repository :where (and (= forge $s1) (= owner $s2) (= name $s3))] "gitlab.com" "nshephard" "emacs")
  #f(compiled-function (&rest rest) "((host owner name) &optional remote demand)\n\nReturn the repository identified by HOST, OWNER and NAME." #<bytecode -0x7d09c81ac132bf7>)(("gitlab.com" "nshephard" "emacs") "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 -0x7d09c81ac132bf7>) ("gitlab.com" "nshephard" "emacs") ("origin" full))
  forge-get-repository(("gitlab.com" "nshephard" "emacs") "origin" full)
  #f(compiled-function (url &optional remote demand) "Return the repository at URL." #<bytecode -0x1460a42b6160b01e>)("git@gitlab.com:nshephard/emacs.git" "origin" full)
  apply(#f(compiled-function (url &optional remote demand) "Return the repository at URL." #<bytecode -0x1460a42b6160b01e>) "git@gitlab.com:nshephard/emacs.git" ("origin" full))
  forge-get-repository("git@gitlab.com:nshephard/emacs.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 0x1318bb2f75ec0525>)(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 0x1318bb2f75ec0525>) full nil)
  forge-get-repository(full)
  forge-pull(nil nil)
  funcall-interactively(forge-pull nil nil)
  call-interactively(forge-pull nil nil)
  command-execute(forge-pull)

This is using...

emacsql-version is a variable defined in ‘emacsql.el’.

Its value is "3.0.0"

Not documented as a variable.

  This variable may be risky if used as a file-local variable.
slackline commented 2 years ago

I found a solution to this problem thanks to the post in this thread.

I deleted the existing emacsql-sqlite-[INSTALLED-VERSION]/sqlite/emacsql-sqlite and recompiled the binary by running make in the directory and all of a sudden org-roam and forge worked without issues. Happy days :smile:

Hope this is useful to anyone else encountering the issue.

meedstrom commented 2 years ago

Like @slackline, I was saved by that Reddit thread. Running (emacsql-sqlite-compile) fixed my org-roam.

The error message is unhelpful ("Selecting deleted buffer"), and it's got to frustrate a large number of users who can't fix it. Toggling toggle-debug-on-error lets us know it's got to do with emacsql, which can eventually lead to the fix with some google-fu, but a minority of users are that savvy.

What if we put in a warning in emacsql to say that the sqlite binary isn't compiled, before something tries to use it?

rodrigomorales1 commented 2 years ago

I had the same issue. The cause was that I had incorrectly written the name of the database to which I wanted to connect.

I had written `my-database (see below)

(defvar db (emacsql-mysql
            "my-database"
            :user "myuser"
            :password "mypassword"))

instead of my_database (see below)

(defvar db (emacsql-mysql
            "my_database"
            :user "myuser"
            :password "mypassword"))

The same error is reported if you have incorrectly written your user or password, so make sure that that information is correctly written.

tarsius commented 2 years ago

2fa32d2ab7a8542091868f475716c707acc5eca0 should fix that. Also see #60 and #62.