mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-26 01:17:51 +08:00
Tools: make Python import error more readable
The problem with printing the exception was that starting with
Python 3.6 the ImportError is yet another (sub) exception called
ModuleNotFoundError which can't be printed as a string and then triggers
another exception:
```
Traceback (most recent call last):
File "/home/julianoes/src/Firmware/Tools/serial/generate_config.py", line 11, in <module>
import jinja2
ModuleNotFoundError: No module named 'jinja2'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/julianoes/src/Firmware/Tools/serial/generate_config.py", line 13, in <module>
print("Failed to import jinja2: " + e)
TypeError: must be str, not ModuleNotFoundError
```
As per @bkueng's suggestion the easiest is to cast the exception to str
and that way prevent the second exception.
This commit is contained in:
@@ -43,31 +43,26 @@ import shutil
|
||||
import filecmp
|
||||
import argparse
|
||||
import sys
|
||||
import errno
|
||||
|
||||
try:
|
||||
import em
|
||||
except ImportError as e:
|
||||
print("Python import error: ", e)
|
||||
print('''
|
||||
Required python package empy not installed.
|
||||
|
||||
Please run:
|
||||
pip3 install --user empy
|
||||
''')
|
||||
exit(1)
|
||||
print("Failed to import em: " + str(e))
|
||||
print("")
|
||||
print("You may need to install it using:")
|
||||
print(" pip3 install --user empy")
|
||||
print("")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
import genmsg.template_tools
|
||||
except ImportError as e:
|
||||
print("Python import error: ", e)
|
||||
print('''
|
||||
Required python package pyros-genmsg not installed.
|
||||
|
||||
Please run:
|
||||
pip3 install --user pyros-genmsg
|
||||
''')
|
||||
exit(1)
|
||||
print("Failed to import genmsg: " + str(e))
|
||||
print("")
|
||||
print("You may need to install it using:")
|
||||
print(" pip3 install --user pyros-genmsg")
|
||||
print("")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
__author__ = "Sergey Belash, Thomas Gubler, Beat Kueng"
|
||||
|
||||
Reference in New Issue
Block a user