From 0a7ec501356f635f99d575306b6d4e14a8059dc3 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Tue, 24 Nov 2015 12:30:05 -0500 Subject: [PATCH] Fail early if no data is found in the database For the run_time graph subcommand if invalid user input was recieved and there was no data in the database we previously would continue running until something in the data processing would raise an exception because there was no data present. This error was often cryptic and hard to debug. This commit fixes this by checking if data is returned from the db api calls and if it's not then we print an error message explaining what data was not found and exit with a non-zero code. Change-Id: I460679f90a46244ee0c0818bf7b3deee4cce280c --- subunit2sql/analysis/run_time.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/subunit2sql/analysis/run_time.py b/subunit2sql/analysis/run_time.py index d7a42a4..b26ad25 100644 --- a/subunit2sql/analysis/run_time.py +++ b/subunit2sql/analysis/run_time.py @@ -36,7 +36,14 @@ def set_cli_opts(parser): def generate_series(): session = api.get_session() test_id = api.get_id_from_test_id(CONF.command.test_id, session) + if not test_id: + print("The test_id %s was not found in the database" % + CONF.command.test_id) + exit(2) run_times = api.get_test_run_time_series(test_id, session) + if not run_times: + print("There was no data found in the database") + exit(3) if not CONF.title: test = api.get_test_by_id(test_id, session) session.close()