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

Do not silently swallow import errors in non-prod environments #22

Open
logannc opened this issue Jun 12, 2018 · 5 comments · May be fixed by #26
Open

Do not silently swallow import errors in non-prod environments #22

logannc opened this issue Jun 12, 2018 · 5 comments · May be fixed by #26

Comments

@logannc
Copy link
Contributor

logannc commented Jun 12, 2018

try:
      import jsx_props
      self.default_props = jsx_props.__dict__.get('init%s'%name, dict)
    except ImportError:
      pass

Do not silently swallow import errors in non-prod environments.

@keredson
Copy link
Owner

defining jsx_props is optional. what should we do if it's not there?

@logannc
Copy link
Contributor Author

logannc commented Jul 17, 2018

This was poorly explained. The idea was to separate finding jsx_props and loading it so that we don't silence errors in jsx_props itself.

I'm not sure what the best mechanism is, but something like this would work:

import importlib

jsx_props_exists = importlib.util.find_spec('jsx_props')
if jsx_props_exists:
  import jsx_props
  self.default_props = jsx_props.__dict__.get('init%s'%name, dict)

@keredson
Copy link
Owner

ah. yeah, that makes sense

@logannc logannc linked a pull request Jul 17, 2018 that will close this issue
@keredson
Copy link
Owner

it seems that python already does this:

$ python
Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import bad
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "bad.py", line 4
    def ():
        ^
SyntaxError: invalid syntax
>>> 
>>> import good
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named good
>>> 

note the two different exception types

@logannc
Copy link
Contributor Author

logannc commented Jul 17, 2018

Not if the error in bad is an ImportError.

logan@logan-desktop:~/.../pyapp$ python
Python 3.5.3 (default, Nov 23 2017, 11:34:05) 
[GCC 6.3.0 20170406] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import bad
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/logan/.../pyapp/bad.py", line 1, in <module>
    import idontexist
ImportError: No module named 'idontexist'
>>> 
logan@logan-desktop:~/.../pyapp$ cat bad.py 
import idontexist

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

Successfully merging a pull request may close this issue.

2 participants