Skip to content

ImportError masks original exception #281

Open
@rittneje

Description

raise ImportError("Failed to import module '%s': %s" % (module_path, e))

If importing the main module fails, this takes the original exception, converts to to a string, and then appends to the ImportError, which masks details about the original exception, including its actual stack trace, and the type of exception.

As an example, suppose my main module does os.environ["ABC"], where there is no ABC environment variable. With the current code, I get:

Runtime.ImportModuleError: Unable to import module 'newrelic_lambda_wrapper': Failed to import module '<name>': 'ABC'

That does not make it clear at all what the problem is, or even that it was a KeyError.

Ideally, this wrapper would instead do something like:

raise ImportError("Failed to import module '%s'" % module_path) from e

Unfortunately, it sounds like the Lambda runtime neglects to output the exception chain properly. https://stackoverflow.com/questions/62112585/aws-lambda-not-showing-cause-exception-stacktrace-in-python-3-8

So this wrapper may instead need to collect the traceback (and exception type) itself, and glue all of that into the ImportModuleError.

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions