Skip to content

Commit

Permalink
Catch TypeError when plot data is None (#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
leplatrem authored Oct 13, 2020
1 parent b1ce386 commit 68d18a4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion poucave/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def _log_result(event, payload):
if check.plot is not None:
try:
infos["plot"] = float(utils.extract_json(check.plot, result["data"]))
except ValueError as e:
except (ValueError, TypeError) as e:
# Ignore errors on checks which return error string in data on failure.
logger.warning(e)

Expand Down
6 changes: 6 additions & 0 deletions tests/test_basic_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,13 @@ async def test_logging_result(caplog, cli, mock_aioresponses):
mock_aioresponses.get(
"http://server.local/__heartbeat__", status=503, payload="Boom"
)
# Return null value.
mock_aioresponses.get("http://server.local/__heartbeat__", payload={"field": None})

await cli.get("/checks/project/plot")
await cli.get("/checks/project/plot")
await cli.get("/checks/project/plot")
await cli.get("/checks/project/plot")

result_logs = [log for log in caplog.records if log.name == "check.result"]

Expand All @@ -370,6 +373,9 @@ async def test_logging_result(caplog, cli, mock_aioresponses):
assert result_logs[2].plot is None
assert result_logs[2].data == '"Boom"'

assert result_logs[3].plot is None
assert result_logs[3].data == '{"field": null}'


async def test_cors_enabled(cli):
response = await cli.get("/", headers={"Origin": "http://example.org"})
Expand Down

0 comments on commit 68d18a4

Please sign in to comment.