Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

catch RecursionError when not in project directory and give more informative error message? #16

Open
NickleDave opened this issue Jul 27, 2020 · 2 comments

Comments

@NickleDave
Copy link

NickleDave commented Jul 27, 2020

Hi @chendaniely thank you for putting pyprojroot together, I use it all the time now

Just ran into an issue where I was outside my project direct (without realizing it) and got a cryptic RecursionError

     16         if len(found) > 0:
     17             return path
---> 18     return py_project_root(path.parent, project_files)
     19
     20

RecursionError: maximum recursion depth exceeded while calling a Python object

Obviously it's my fault for being in the wrong directory.

But I wonder if there's a way to catch this and give a user a more informative error message though?
i.e. something like

try:
    return py_project_root(path.parent, project_files)
except RecursionError as e:
    print("did not find project root, are you in the project directory?")
    raise e

(I don't know if that's an idiomatic way to add info and re-raise the error, but something like that which gives a little more info to a user that might be lost in some other problem and confused by the error, like me 🙂 )

Just a suggestion. Thanks!

@NickleDave
Copy link
Author

NickleDave commented Jul 27, 2020

added context:
this happens because I have my project installed into an environment, and I'm importing it outside the directory.
Within the project itself there's a "core" package that uses pyprojroot to get some data the package uses.
I.e.,

src/
  my_package/
    some_module.py
      data = pyprojroot.here.joinpath('/data/list_of_files.txt')

so maybe this is an edge case that would be better solved by me just keeping the data file inside the package.
Feel free to not fix if you don't feel like it's worth handling that edge case.
Anyways now you have an issue about it; in case anyone else has my brilliant idea they can find it.

@majidaldo
Copy link

majidaldo commented Aug 22, 2020

ah same problem #17 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants