atilaneves/cmake-ide

"Wrong type argument: hash-table-p, nil" when opening non-CMake files

cyrus-and opened this issue · 20 comments

Just open a standalone C file and the following happens:

cmake-ide [Fri Dec  8 22:04:56 2017]: Making directory /tmp/cmakeyTKBVQ
cmake-ide [Fri Dec  8 22:04:57 2017]: Starting rdm server
cmake-ide [Fri Dec  8 22:04:57 2017]: Running cmake for src path /home/cyrus/tmp/ in build path /tmp/cmakeyTKBVQ/
cmake-ide [Fri Dec  8 22:04:57 2017]: Finished running CMake
cmake-ide [Fri Dec  8 22:04:57 2017]: Non-existent compilation DB file /tmp/cmakeyTKBVQ/compile_commands.json
error in process sentinel: cmake-ide--idb-file-to-obj: Wrong type argument: hash-table-p, nil
error in process sentinel: Wrong type argument: hash-table-p, nil

IMHO cmake-ide should do nothing at all (especially starting rdm and creating build directories) if it cannot find a suitable environment first.

This seems related to: #93 and #111.


Relevant configuration:

(require 'rtags)
(cmake-ide-setup)
(rtags-enable-standard-keybindings)
  • GNU Emacs 26.0.90
  • cmake-ide from MELPA
  • Debian GNU/Linux 9

I also encountered the same problem.

dlyr commented

Could you test with my fork of cmake-ide ? I have maybe fixed this ...
It's the branch wip_project_key here
https://github.com/dlyr/cmake-ide/tree/wip_project_key

Alright this issue has been introduced in 99bfce8 apparently and @dlyr your PR seems to fix it, although a bunch of weird messages are logged:

cmake-ide [Mon Dec 11 18:04:05 2017]: locate cmakelists new-dir [nil]
cmake-ide [Mon Dec 11 18:04:05 2017]: locate-project-dir : [nil][nil]
cmake-ide [Mon Dec 11 18:04:05 2017]: Current project is not a cmake project
cmake-ide [Mon Dec 11 18:04:05 2017]: Not a cmake project
cmake-ide [Mon Dec 11 18:04:05 2017]: puthash for cmake-ide [Mon Dec 11 18:04:05 2017]: Not a cmake project /var/folders/jb/b_c1572j103c989nd69w6sch0000gn/T/cmakeBM8YtP
cmake-ide [Mon Dec 11 18:04:05 2017]: locate cmakelists new-dir [nil]
cmake-ide [Mon Dec 11 18:04:05 2017]: locate-project-dir : [nil][nil]
cmake-ide [Mon Dec 11 18:04:05 2017]: Current project is not a cmake project
cmake-ide [Mon Dec 11 18:04:05 2017]: Making directory /var/folders/jb/b_c1572j103c989nd69w6sch0000gn/T/cmakeBM8YtP
cmake-ide [Mon Dec 11 18:04:05 2017]: locate cmakelists new-dir [nil] [2 times]
cmake-ide [Mon Dec 11 18:04:05 2017]: locate-project-dir : [nil][nil]
cmake-ide [Mon Dec 11 18:04:05 2017]: Current project is not a cmake project
cmake-ide [Mon Dec 11 18:04:05 2017]: Not a cmake project
cmake-ide [Mon Dec 11 18:04:05 2017]: locate cmakelists new-dir [nil]
cmake-ide [Mon Dec 11 18:04:05 2017]: locate-project-dir : [nil][nil]
cmake-ide [Mon Dec 11 18:04:05 2017]: Current project is not a cmake project
cmake-ide [Mon Dec 11 18:04:05 2017]: locate cmakelists new-dir [nil] [2 times]
cmake-ide [Mon Dec 11 18:04:05 2017]: locate-project-dir : [nil][nil]
cmake-ide [Mon Dec 11 18:04:05 2017]: Current project is not a cmake project
cmake-ide [Mon Dec 11 18:04:05 2017]: Not a cmake project
cmake-ide [Mon Dec 11 18:04:05 2017]: locate cmakelists new-dir [nil]
cmake-ide [Mon Dec 11 18:04:05 2017]: locate-project-dir : [nil][nil]
cmake-ide [Mon Dec 11 18:04:05 2017]: Current project is not a cmake project
cmake-ide [Mon Dec 11 18:04:05 2017]: locate cmakelists new-dir [nil]
cmake-ide [Mon Dec 11 18:04:05 2017]: locate-project-dir : [nil][nil]
cmake-ide [Mon Dec 11 18:04:05 2017]: Current project is not a cmake project

Plus this happens when I rtags-find-symbol-at-point:

error in process sentinel: not: Symbol’s function definition is void: string-empty-p
error in process sentinel: Symbol’s function definition is void: string-empty-p

But that's another issue.

dlyr commented

Yeah the locate message are for debug purpose (I will remove them soon I hope).
the Current projet is not a cmake project will stay to inform that cmake-ide functionalities are not available.
I will check the rtag thing ;)

dlyr commented

By the way what did you expect from rtags ?
Mine say
No buffer named "Can't seem to connect to server (/run/user/1000/rdm.socket)Can't seem to connect to server (/run/user/1000/rdm.socket)Can't seem to connect to server (/run/user/1000/rdm.socket)
"
And if a run rdm myself
I have No buffer named "[A directory of a former project]/Not indexed
"

To jump to the symbol under the point, which works indeed but then that error appears.

You need to install rtags both the program and the Emacs package.

dlyr commented

(rtags works well for me with an cmake-ide project)
Do you generate a compile-commands.json ?

@dlyr it's performed automatically and it works with master.

Here's the stack trace:

Debugger entered--Lisp error: (void-function string-empty-p)
  (string-empty-p (cmake-ide--buffer-string buffer))
  (not (string-empty-p (cmake-ide--buffer-string buffer)))
  (and (not (string-empty-p (cmake-ide--buffer-string buffer))) (not cmake-ide-header-no-flags))
  (if (and (not (string-empty-p (cmake-ide--buffer-string buffer))) (not cmake-ide-header-no-flags)) (progn (cond (cmake-ide-try-unique-compiler-flags-for-headers (cmake-ide--hdr-try-unique-compiler-flags idb buffer sys-includes)) ((cmake-ide--hdr-ask-ninja-and-make idb buffer sys-includes) t) (t (cmake-ide--hdr-legacy idb buffer sys-includes)))))
  cmake-ide--set-flags-for-hdr-file(#<hash-table equal 14/65 0x16d04e5> #<buffer handler.h> nil)
  (if (cmake-ide--is-src-file file-name) (cmake-ide--set-flags-for-src-file file-params buffer sys-includes) (cmake-ide--set-flags-for-hdr-file idb buffer (cmake-ide--flags-to-sys-includes hdr-flags)))
  (let* ((file-name (buffer-file-name buffer)) (file-params (cmake-ide--idb-file-to-obj idb file-name)) (sys-includes (cmake-ide--params-to-sys-includes file-params)) (commands (cmake-ide--idb-all-commands idb)) (hdr-flags (cmake-ide--commands-to-hdr-flags commands))) (cmake-ide--message "Setting flags for file %s" file-name) (if (cmake-ide--is-src-file file-name) (cmake-ide--set-flags-for-src-file file-params buffer sys-includes) (cmake-ide--set-flags-for-hdr-file idb buffer (cmake-ide--flags-to-sys-includes hdr-flags))))
  cmake-ide--set-flags-for-file(#<hash-table equal 14/65 0x16d04e5> #<buffer handler.h>)
  (closure ((idb . #<hash-table equal 14/65 0x16d04e5>) cmake-ide--semantic-system-include t) (x) (cmake-ide--set-flags-for-file idb x))(#<buffer handler.h>)
  mapc((closure ((idb . #<hash-table equal 14/65 0x16d04e5>) cmake-ide--semantic-system-include t) (x) (cmake-ide--set-flags-for-file idb x)) (#<buffer handler.h>))
  (let* ((idb (cmake-ide--cdb-json-file-to-idb)) (set-flags (function (lambda (x) (cmake-ide--set-flags-for-file idb x))))) (mapc set-flags cmake-ide--src-buffers) (mapc set-flags cmake-ide--hdr-buffers) (setq cmake-ide--src-buffers nil cmake-ide--hdr-buffers nil) (cmake-ide--run-rc))
  cmake-ide--on-cmake-finished()
  (closure (cmake-ide--semantic-system-include t) (_process _event) (cmake-ide--message "Finished running CMake") (cmake-ide--on-cmake-finished))(#<process cmake> "finished\n")

(Feel free to move this thread to a new issue if you want.)

dlyr commented

hum, I don't know and it work on my project, could you post a minimal example to reproduce the bug ?
string-empty-p is defined in subr (you need to include/install subr-x somewhere)
but that's strang it works on master which also use this function ...

  1. start Emacs with env HOME=/tmp/ emacs -Q;

  2. paste the following in the scratch buffer then M-x eval-buffer:

    (package-initialize)
    
    (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
    
    (package-refresh-contents)
    
    (package-install-file "/path/to/your/cmake-ide.el")
    (package-install 'rtags)
    
    (require 'rtags)
    (cmake-ide-setup)
  3. clone this repo somewhere;

  4. back to Emacs open /path/to/repo/src/main.c;

  5. move the point on line 7 over zz_handler;

  6. M-x rtags-find-symbol-at-point the file handler.h is visited and the error triggers.

I just noticed that this happens the first time only.

dlyr commented

if you add
(require 'subr-x)
above (cmake-ide-setup) it works right ?
This should definitively be setup in cmake-ide (see #55 #127)
I have tested something here to load subr-x but if fails try to define empty-string-p. Since I quite new to emacs-lisp, it might not be the right way to do this.

it works right ?

Yeps.

dlyr commented

error in process sentinel: Wrong type argument: hash-table-p, nil

Just for the record: This also happens if you use in-source-build. I.e. CMakeCache.txt is already existent in the source dir. So compile_commands.json is also generated in the source dir.

I kind of lost track of this... but it seems that the original error ("Wrong type argument: hash-table-p, nil") does not happen anymore. Can you confirm?

@juergenhoetzel See PR #185 for the problem that happens if a build exists in the source directory.

skrat commented

This is still a problem when following the installation and usage manual. My impression so far from using rtags + cmake-ide is that it works less than half of the time and every almost every time I open a source file, I get this error because it can't find the compilation DB, so why doesn't it just fail silently and let me work?

@skrat I'd fix it if I knew what was going on. I haven't been able to reproduce it.

skrat commented

@atilaneves I'm more than happy to assist, I'm on Emacs 27, this is the stack trace:

Debugger entered--Lisp error: (wrong-type-argument hash-table-p nil)
  gethash("/home/skrat/Workspace/xxx/lightmapper/src/li..." nil)
  cide--idb-file-to-obj(nil "/home/skrat/Workspace/xxx/lightmapper/src/li...")
  cide--set-flags-for-file(nil #<buffer lightmapper.cpp>)
  #f(compiled-function (x) #<bytecode 0x158d22f1f4e9>)(#<buffer lightmapper.cpp>)
  mapc(#f(compiled-function (x) #<bytecode 0x158d22f1f4e9>) (#<buffer lightmapper.cpp>))
  cide--on-cmake-finished()
  cmake-ide-load-db()
  funcall-interactively(cmake-ide-load-db)
  call-interactively(cmake-ide-load-db record nil)
  command-execute(cmake-ide-load-db record)
  #f(compiled-function (cmd) #<bytecode 0x158d228f8d6d>)("cmake-ide-load-db")
  ivy-call()
  ivy-read("M-x " ("cmake-ide-load-db" "diff-hl-mode" "c++-mode" "rtags-restart-process" "rtags-find-symbol-at-point" "man" "calc" "cmake-ide-compile" "counsel-package" "eldoc-mode" "package-install" "package-delete" "counsel-unicode-char" "mu4e" "which-key-show-major-mode" "tide-mode" "package-refresh-contents" "ielm" "list-packages" "describe-function" "rtags-find-references" "load-theme" "eglot" "ibuffer" "irony-mode" "insert-char" "ivy-rich-mode" "paredit-mode" "customize-variable" "add-dir-local-variable" "eshell" "irony-eldoc" "customize-group" "describe-variable" "imenu" "tide-setup" "describe-mode" "form-feed-mode" "counsel-ibuffer" "rtags-is-running" "package-autoremove" "irony-install-server" "rainbow-delimiters-mode" "smex" "swiper" "csharp-mode" "company-mode" "delete-window" "flycheck-mode" "auto-fill-mode" ...) :predicate nil :require-match t :history counsel-M-x-history :action #f(compiled-function (cmd) #<bytecode 0x158d228f8d6d>) :sort nil :keymap (keymap (67108908 . counsel--info-lookup-symbol) (67108910 . counsel-find-symbol)) :initial-input nil :caller counsel-M-x)
  counsel-M-x()
  funcall-interactively(counsel-M-x)
  call-interactively(counsel-M-x nil nil)
  command-execute(counsel-M-x)

@skrat Thanks, that helps but I still don't know how to reproduce it. It'd be easier if someone who can would debug.