1

I have this code that used to work fine until today:

(let* ((newest-pkg (cadr (assq 'org package-archive-contents)))
       (installed-pkg (cadr (or (assq 'org package-alist)
                               (assq 'org package--builtins)))))
  (when (version-list-<= (package-desc-version newest-pkg) (package-desc-version installed-pkg))
    ;; Instalamos la nueva versión de org-mode
    ;;(package-install newest-pkg)
    (message (format "Paquete «%s» actualizado de la versión %s a la versión %s"
                     (package-desc-name newest-pkg)
                     (car (package-desc-version newest-pkg))
                     (car (package-desc-version installed-pkg))))
    ;;(delete-directory (package-desc-dir installed-pkg) t)
    ))

However, it is failing with this error:

Debugger entered--Lisp error: (wrong-type-argument listp [nil nil "Outline-based notes management and organizer"])
  cadr((org . [nil nil "Outline-based notes management and organizer"]))
  (let* ((newest-pkg (cadr (assq (quote org) package-archive-contents))) (installed-pkg (cadr (or (assq (quote org) package-alist) (assq (quote org) package--builtins))))) (if (version-list-<= (progn (or (and (memq (aref newest-pkg 0) cl-struct-package-desc-tags)) (error "%s accessing a non-%s" (quote package-desc-version) (quote package-desc))) (aref newest-pkg 2)) (progn (or (and (memq (aref installed-pkg 0) cl-struct-package-desc-tags)) (error "%s accessing a non-%s" (quote package-desc-version) (quote package-desc))) (aref installed-pkg 2))) (progn (message (format "Paquete «%s» actualizado de la versión %s a la versión %s" (progn (or (and ...) (error "%s accessing a non-%s" ... ...)) (aref newest-pkg 1)) (car (progn (or ... ...) (aref newest-pkg 2))) (car (progn (or ... ...) (aref installed-pkg 2))))))))
  eval((let* ((newest-pkg (cadr (assq (quote org) package-archive-contents))) (installed-pkg (cadr (or (assq (quote org) package-alist) (assq (quote org) package--builtins))))) (if (version-list-<= (progn (or (and (memq (aref newest-pkg 0) cl-struct-package-desc-tags)) (error "%s accessing a non-%s" (quote package-desc-version) (quote package-desc))) (aref newest-pkg 2)) (progn (or (and (memq (aref installed-pkg 0) cl-struct-package-desc-tags)) (error "%s accessing a non-%s" (quote package-desc-version) (quote package-desc))) (aref installed-pkg 2))) (progn (message (format "Paquete «%s» actualizado de la versión %s a la versión %s" (progn (or (and ...) (error "%s accessing a non-%s" ... ...)) (aref newest-pkg 1)) (car (progn (or ... ...) (aref newest-pkg 2))) (car (progn (or ... ...) (aref installed-pkg 2)))))))) nil)
  eval-last-sexp-1(nil)
  eval-last-sexp(nil)
  call-interactively(eval-last-sexp nil nil)
  command-execute(eval-last-sexp)

What am I doing wrong?

EDIT: This is how I'm setting the package archive.

(setf package-enable-at-startup nil)
(package-initialize)
(setf package-archives '(("melpa" . "https://melpa.org/packages/")
                         ("org" . "http://orgmode.org/elpa/")
                         ("gnu" . "https://elpa.gnu.org/packages/")))

(unless package-archive-contents
  (package-refresh-contents))

My Emacs version is GNU Emacs 24.5.1 (i686-pc-linux-gnu, GTK+ Version 3.20.6) of 2016-06-04 on juergen.

4
  • What is your emacs version and how are you setting up packages repositories? (e.g. what is the value of package-archives and do you call package-refresh-contents prior to this? etc.) It appears as though your package-archive-contents might contain a list of conses instead of a list of lists, which I can't reproduce on emacs 24.5
    – nispio
    Jun 17, 2016 at 20:01
  • @nispio I edited the question, and I call that code after package-refresh-contents.
    – shackra
    Jun 17, 2016 at 20:08
  • 1
    Still unable to reproduce. You might consider wiping out ~/.emacs.d/elpa and restarting emacs to see if the problem goes away.
    – nispio
    Jun 17, 2016 at 20:17
  • 2
    You could insert a call to (debug) in that code, or if it is in a function you can you could just use M-x debug-on-entry for that function. You can put (debug) into the first let* binding using progn: (progn (debug) (newest-pkg (cadr (assq 'org package-archive-contents)))). Then step through the debugger to see which cadr is the problem. That might give you a clue. But I'd start by doing what @nispio suggested - simplify your debugging context.
    – Drew
    Jun 17, 2016 at 22:54

1 Answer 1

2

Looking at the documentation for the following three variables, they have slightly different formats:

package-archive-contents

This is an alist mapping package names (symbols) to non-empty lists of `package-desc' structures.

package-alist

Each element has the form (PKG . DESCS), where PKG is a package name (a symbol) and DESCS is a non-empty list of `package-desc'structure, sorted by decreasing versions.

package--builtins

Each element has the form (PKG . PACKAGE-BI-DESC), where PKG is a package name (a symbol) and DESC is a `package--bi-desc' structure.

So package--builtins needs to be handled a little differently because the cdr of each element is not a list like the other two. Instead, you should be able to make it work like this:

(let* ((newest-pkg (car-safe (cdr (assq 'org package-archive-contents))))
       (new-ver (and newest-pkg (package-desc-version newest-pkg)))
       (builtin-pkg (cdr (assq 'org package--builtins)))
       (installed-pkg (car-safe (cdr (assq 'org package-alist))))
       (old-dir (and installed-pkg (package-desc-dir installed-pkg)))
       (old-ver (or (and installed-pkg (package-desc-version installed-pkg))
                    (and builtin-pkg (package--bi-desc-version builtin-pkg)))))
  (when (and new-ver (version-list-< old-ver new-ver))
    ;; Instalamos la nueva versión de org-mode
    ;;(package-install newest-pkg)
    (message (format "Paquete «%s» actualizado de la versión %s a la versión %s"
                     (package-desc-name newest-pkg) old-ver new-ver))
    ;; (when old-dir (delete-directory old-dir t))
    ))
6
  • I'm getting a different error this time: Debugger entered--Lisp error: (error "package-desc-version accessing a non-package-desc") signal(error ("package-desc-version accessing a non-package-desc")) error("%s accessing a non-%s" package-desc-version package-desc)
    – shackra
    Jun 18, 2016 at 20:34
  • I'm using package-desc-p just to be sure that installed-pkg is a valid package-desc
    – shackra
    Jun 18, 2016 at 20:44
  • 1
    @shackra I have updated the code to add in a large amount of error checking along the way.
    – nispio
    Jun 18, 2016 at 21:19
  • I was trying by my own too but things didn't worked out, this is a function I made for using inside let* for the installed-pkg variable: (defun shackra/update--one-package-installed-package-installed (package) "Retorna un PACKAGE-DESC valido" (or (car-safe (cdr (assq package package-alist))) (if (package-desc-p (cdr (assq package package--builtins))) (cdr (assq package package--builtins)) (package-desc-create :name (format "%s" package) :version (list 0 0)))))
    – shackra
    Jun 18, 2016 at 21:34
  • btw, you misspelled pakcage-desc-version
    – shackra
    Jun 18, 2016 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.