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

Impossible to debug menu.py errors #44

Open
MarZab opened this issue Mar 2, 2016 · 3 comments
Open

Impossible to debug menu.py errors #44

MarZab opened this issue Mar 2, 2016 · 3 comments
Labels
bug Something doesn't work the way it should

Comments

@MarZab
Copy link

MarZab commented Mar 2, 2016

menu.py importing has a catch all that hides all errors making you think the plugin is not working when your code is at fault

https://github.com/borgstrom/django-simple-menu/blob/master/menu/menu.py#L75

My snippet:

        try:
            __import__(menu_module, fromlist=["menu", ])
        except ImportError as err:
            traceback.print_tb(err.__traceback__)
            pass
@borgstrom
Copy link
Collaborator

borgstrom commented Mar 2, 2016 via email

@borgstrom
Copy link
Collaborator

It appears the problem is not that you can't debug all problems when we import the menus, it's that you cannot debug other ImportErrors

If I make a syntax error in the accounts/menus.py file in the example project then I get the correct debug page:

screen shot 2016-03-02 at 8 24 53 pm

However, if I change it so there's a bad import:

diff --git a/example/accounts/menus.py b/example/accounts/menus.py
index 4b0d5b8..e44c03c 100644
--- a/example/accounts/menus.py
+++ b/example/accounts/menus.py
@@ -1,4 +1,4 @@
-from django.core.urlresolvers import reverse
+from django.core.urlresolvers import reverse_NOPE

 from menu import Menu, MenuItem

Then the page loads and there's silently no accounts menu anymore.

Since we also get an ImportError when there's no menus.py file inside an installed app I don't want to make the logging too verbose here.

@kytta
Copy link
Member

kytta commented May 8, 2022

What if we filter the exceptions to find out where it's coming from? Something along the lines of:

# https://github.com/jazzband/django-simple-menu/blob/21136c30d8dc064f5b587272012301694307c9d5/menu/menu.py#L66
try:
    __import__(menu_module, fromlist=["menu", ])
except ImportError as err:
   if err.name != menu_module:
       raise ImportError from err

This way, importing non-existent app.menus will not throw exception, but incorrect import inside app.menus will

@kytta kytta added the bug Something doesn't work the way it should label May 8, 2022
@kytta kytta added this to the v2.0.0 milestone May 9, 2022
@kytta kytta removed this from the v2.1.0 milestone Nov 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something doesn't work the way it should
Projects
None yet
Development

No branches or pull requests

3 participants