Skip to content

Commit de86349

Browse files
authored
Merge pull request #273 from circulon/fix/init_start_logging
fixed app imort failures not being logged
2 parents b4f704c + d8cad14 commit de86349

3 files changed

Lines changed: 20 additions & 12 deletions

File tree

.github/workflows/tests.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ jobs:
1212
- { name: "3.9", python: "3.9", os: ubuntu-latest }
1313
- { name: "3.8", python: "3.8", os: ubuntu-latest }
1414
steps:
15-
- uses: actions/checkout@v2
15+
- uses: actions/checkout@v4
1616

17-
- uses: actions/setup-node@v2
17+
- uses: actions/setup-node@v4
1818
with:
1919
node-version: "14"
2020
- run: npm install
2121

22-
- uses: actions/setup-python@v2
22+
- uses: actions/setup-python@v4
2323
with:
2424
python-version: ${{ matrix.python }}
2525
- name: update pip
@@ -43,7 +43,7 @@ jobs:
4343
- run: npm run pytest
4444
- run: npm run pylint
4545

46-
- uses: codecov/codecov-action@v2
46+
- uses: codecov/codecov-action@v4
4747
with:
4848
token: "89d22de7-bfaf-43a0-81da-33cc733fd294"
4949
fail_ci_if_error: true

wsgi_handler.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
import importlib
1010
import io
1111
import json
12+
import logging
1213
import os
1314
import sys
1415
import traceback
16+
from werkzeug.exceptions import InternalServerError
1517

1618
# Call decompression helper from `serverless-python-requirements` if
1719
# available. See: https://github.com/UnitedIncome/serverless-python-requirements#dealing-with-lambdas-size-limitations
@@ -43,9 +45,9 @@ def import_app(config):
4345
wsgi_module = importlib.import_module(wsgi_fqn_parts[-1])
4446

4547
return getattr(wsgi_module, wsgi_fqn[1])
46-
except: # noqa
47-
traceback.print_exc()
48-
raise Exception("Unable to import {}".format(config["app"]))
48+
except Exception as err:
49+
logging.exception("Unable to import app: '{}' - {}".format(config["app"], err))
50+
return InternalServerError("Unable to import app: {}".format(config["app"]))
4951

5052

5153
def append_text_mime_types(config):

wsgi_handler_test.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -812,11 +812,17 @@ def test_command_unknown(mock_wsgi_app_file, mock_app, wsgi_handler):
812812
assert "Exception: Unknown command: unknown" in response[1]
813813

814814

815-
def test_app_import_error(mock_wsgi_app_file, mock_app_with_import_error, event_v1):
816-
with pytest.raises(Exception, match="Unable to import app.app"):
817-
if "wsgi_handler" in sys.modules:
818-
del sys.modules["wsgi_handler"]
819-
import wsgi_handler # noqa: F401
815+
def test_app_import_error(mock_wsgi_app_file, mock_app_with_import_error, event_v1, wsgi_handler):
816+
response = wsgi_handler.handler(event_v1, {})
817+
assert response == {
818+
"statusCode": 500,
819+
"body": "<!doctype html>\n<html lang=en>\n<title>500 Internal Server Error</title>\n<h1>Internal Server Error</h1>\n<p>Unable to import app: app.app</p>\n",
820+
"headers": {
821+
"Content-Type": "text/html; charset=utf-8",
822+
"Content-Length": "140"
823+
},
824+
"isBase64Encoded": False
825+
}
820826

821827

822828
def test_handler_with_encoded_characters_in_path(

0 commit comments

Comments
 (0)