elpy-find-file returns a 'Wrong type argument: stringp, null' error

Created on 16 Oct 2017  路  10Comments  路  Source: jorgenschaefer/elpy

The error message from the messages buffer is ffip-project-root: Wrong type argument: stringp, nil

Elpy Configuration

Virtualenv........:  (/home/guruprasad/dev/py/mailadm/venv/)
RPC Python........: 3.6.2 (/home/guruprasad/dev/py/mailadm/venv/bin/python)
Interactive Python: python (/home/guruprasad/dev/py/mailadm/venv/bin/python)
Emacs.............: 25.3.1
Elpy..............: 1.16.1
Jedi..............: 0.11.0
Rope..............: Not found (0.10.7 available)
Importmagic.......: 0.1.7
Autopep8..........: Not found (1.3.3 available)
Yapf..............: Not found (0.19.0 available)
Syntax checker....: flake8 (/home/guruprasad/dev/py/mailadm/venv/bin/flake8)

This happens on my up-to-date Arch Linux installation and looks like a bug.

Bug

All 10 comments

I failed to reproduce the bug on my Arch installation,
could you use M-x toggle-debug-on-error and post the report ?

@galaunay @jorgenschaefer Sorry for the very late update. Here is the log after enabling debug

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  file-name-as-directory(nil)
  ffip-project-root()
  ffip-get-project-root-directory()
  ffip-project-search(nil nil)
  ffip-find-files(nil nil)
  find-file-in-project()
  elpy-find-file(nil)
  funcall-interactively(elpy-find-file nil)
  call-interactively(elpy-find-file nil nil)
  command-execute(elpy-find-file)

Could be that the variable ffip-project-root is not initialized correctly in elpy-find-file.

Is M-x find-file-in-project working ?

Could you also post the results of (elpy-project-root) and (print default-directory) while in your project, to help figuring out what happen ?

M-x find-file-in-project doesn't work and fails with the same error.

I ran the following steps after opening a file ~/dev/py/mailadm/mailadm/mailadm/models/meta.py

(elpy-project-root) gives me ~/dev/py/mailadm/mailadm
(print default-directory) gives

"~/dev/py/mailadm/mailadm/mailadm/models/"
"~/dev/py/mailadm/mailadm/mailadm/models/"

This error seems to happen only with projects which have a directory structure with multiple repeating names (for example mailadm/mailadm/mailadm) and works fine everywhere else

I reproduced your file structure, but couldn't reproduce the bug.

But if find-file-in-project doesn't work as well, the bug could be here.
Is the problem also present without elpy mode enabled (with the classical python-mode for example) ?

This issue seems to be the same as https://github.com/technomancy/find-file-in-project/issues/82.

When ffip-project-root is nil and default-directory is not in the directory with VC, find-file-in-project will error with stringp nil.

Is it possible for elpy to detect the project root (say, the topmost python package from the current dir) and set ffip-project-root?

Elpy is already supposed to do that.

Elpy set ffip-project-root with the result of the function (elpy-project-root) before calling find-file-in-project. By default, this function (elpy-project-root) searches for a projectile project, a python package or a VCS repo. (That's why I was curious about its result).

As (elpy-project-root) is working correctly for you, my best guess is that ffip-project-root is overridden somewhere...

What happen if you set ffip-project-root by hand with (setq ffip-project-root "~/dev/py/mailadm/mailadm") and then call find-file-in-project ?
If it is still failing, I really think you should report the bug to find-file-in-project (that is then different of technomancy/find-file-in-project#82).

With find-file-in-project 5.4.4 released a few days ago, I no longer get the error as it uses default-directory if it cannot find a project. But the default-directory is set to the inner-most python package corresponding to the currently open file and not the outermost one.

For example when I have opened ~/dev/py/mailadm/mailadm/mailadm/models/meta.py, elpy-find-file searches only in the models directory. The last mailadm directory is the topmost python package and the penultimate one is what could be used as the project root.

3    Find in models/:

Is there any significance to the 3?

The first number (3 for you) is the number of files found in the project (among which you have to choose).

elpy-find-file uses (elpy-project-root) to find the directory it should search in and fall back to default-directory if it don't find no repo/package.
So if as you said previously:

(elpy-project-root) gives me ~/dev/py/mailadm/mailadm

Elpy should search in ~/dev/py/mailadm/mailadm

I tried again to reproduce the bug with the last version of find-file-in-project (which is 5.4.5 in melpa), the last release of elpy (1.17.0) and your file architecture, without success.

I am running out of ideas for this...
Maybe if you track the value of ffip-project-root during the call of elpy-find-file, you will be able to see where something wrong happen.

I am closing this, please re-open if necessary.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mikeiwi picture mikeiwi  路  5Comments

kirk86 picture kirk86  路  5Comments

Arseny-N picture Arseny-N  路  4Comments

SergiyKolesnikov picture SergiyKolesnikov  路  3Comments

mdk2029 picture mdk2029  路  5Comments