use-package icon indicating copy to clipboard operation
use-package copied to clipboard

"Error (use-package): Cannot load ..." needs to be more helpful

Open aspiers opened this issue 5 years ago • 6 comments

Sometimes use-package reports an error like:

Error (use-package): Cannot load X

without giving any hint on what might be wrong, or any suggestion for what a good next step would be for the user to try. This has caused confusion more than once, e.g.

I think some of these might be related too, at least in terms of the issue that org-plus-contrib is not a valid feature symbol despite being an ELPA package name:

There might be other packages for which this error appears, for different reasons.

Unfortunately I don't know enough to suggest what a more helpful error message would look like, but it does seem like there's room for improvement in the UX here.

aspiers avatar May 14 '19 11:05 aspiers

Ugliest thing is that it's so even with debug-on-error is turned on.

henrymazza avatar Apr 11 '20 18:04 henrymazza

Any thoughts / update on this @jwiegley ? I just ran into this, too, and have no idea how to debug the issue.

andrewbanchich avatar Aug 27 '22 21:08 andrewbanchich

I have this set in my init.el file:

  (if init-file-debug
      (setq use-package-verbose t
            use-package-expand-minimally nil
            use-package-compute-statistics t
            debug-on-error t)
    (setq use-package-verbose nil
          use-package-expand-minimally t))

Then I start up emacs with emacs --debug-init.

jwiegley avatar Aug 29 '22 05:08 jwiegley

It would be great if we could make the error message helpful by default, rather than requiring the user to copy and paste some elisp or perform some other configuration task.

For example, even if for some reason use-package doesn't have access to a relevant error to log, at very least it should externalise some basic information about what it was doing when the failure happened - e.g., was it trying to require that package, or compile it, or something else?

And the error message could also link to a web page / file / buffer / docstring containing some tips and tricks for ways to solve the error.

aspiers avatar Aug 29 '22 11:08 aspiers

@jwiegley @skangas guys, any update on this?

"Error (use-package): Cannot load X"

without any further hints / details is very unhelpul.

Suggestion has 16 thumbs up, could you look into it?

gety9 avatar Jan 27 '24 12:01 gety9

Could you try putting this definition just after you load use-package:

(defun use-package-require (name &optional no-require body)
  (if use-package-expand-minimally
      (use-package-concat
       (unless no-require
         (list (use-package-load-name name)))
       body)
    (if no-require
        body
      (use-package-with-elapsed-timer
          (format "Loading package %s" name)
        `((if (not ,(use-package-load-name name))
              (display-warning 'use-package
                               (format "Cannot load %s" ',name)
                               :error)
            ,@body))))))

It seems that the current definition of this function tells require to not report any errors, but I think perhaps we'd like to make them available.

jwiegley avatar Jan 31 '24 00:01 jwiegley