mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-19 02:53:34 +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:
@@ -16,7 +16,7 @@ from argparse import ArgumentParser
|
||||
try:
|
||||
from pymavlink import mavutil
|
||||
except ImportError as e:
|
||||
print("Failed to import pymavlink: " + e)
|
||||
print("Failed to import pymavlink: " + str(e))
|
||||
print("")
|
||||
print("You may need to install it with:")
|
||||
print(" pip3 install --user pymavlink")
|
||||
@@ -26,7 +26,7 @@ except ImportError as e:
|
||||
try:
|
||||
import serial
|
||||
except ImportError as e:
|
||||
print("Failed to import pyserial: " + e)
|
||||
print("Failed to import pyserial: " + str(e))
|
||||
print("")
|
||||
print("You may need to install it with:")
|
||||
print(" pip3 install --user pyserial")
|
||||
|
||||
@@ -17,7 +17,7 @@ from argparse import ArgumentParser
|
||||
try:
|
||||
from pymavlink import mavutil
|
||||
except ImportError as e:
|
||||
print("Failed to import pymavlink: " + e)
|
||||
print("Failed to import pymavlink: " + str(e))
|
||||
print("")
|
||||
print("You may need to install it with:")
|
||||
print(" pip3 install --user pymavlink")
|
||||
|
||||
@@ -10,7 +10,7 @@ import sys
|
||||
try:
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
except ImportError as e:
|
||||
print("Failed to import jinja2: " + e)
|
||||
print("Failed to import jinja2: " + str(e))
|
||||
print("")
|
||||
print("You may need to install it using:")
|
||||
print(" pip3 install --user jinja2")
|
||||
@@ -20,7 +20,7 @@ except ImportError as e:
|
||||
try:
|
||||
import yaml
|
||||
except ImportError as e:
|
||||
print("Failed to import yaml: " + e)
|
||||
print("Failed to import yaml: " + str(e))
|
||||
print("")
|
||||
print("You may need to install it using:")
|
||||
print(" pip3 install --user pyyaml")
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ import sys
|
||||
try:
|
||||
import requests
|
||||
except ImportError as e:
|
||||
print("Failed to import requests: " + e)
|
||||
print("Failed to import requests: " + str(e))
|
||||
print("")
|
||||
print("You may need to install it using:")
|
||||
print(" pip3 install --user requests")
|
||||
|
||||
@@ -4,13 +4,12 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
|
||||
try:
|
||||
import yaml
|
||||
except ImportError as e:
|
||||
print("Failed to import yaml: " + e)
|
||||
print("Failed to import yaml: " + str(e))
|
||||
print("")
|
||||
print("You may need to install it using:")
|
||||
print(" pip3 install --user pyyaml")
|
||||
@@ -20,7 +19,7 @@ except ImportError as e:
|
||||
try:
|
||||
import cerberus
|
||||
except ImportError as e:
|
||||
print("Failed to import cerberus: " + e)
|
||||
print("Failed to import cerberus: " + str(e))
|
||||
print("")
|
||||
print("You may need to install it using:")
|
||||
print(" pip3 install --user cerberus")
|
||||
|
||||
Reference in New Issue
Block a user