Skip to content

Commit

Permalink
vdk-control-cli: improve execute error handling
Browse files Browse the repository at this point in the history
When an exception occurs while the `vdkcli execute`
command is used, we print the whole stack trace in the
terminal, which is not user-friendly, and could cause
confusion.

This change adds error handling to the execute command
that provides more manageable error message, and avoids
printing the whole stack trace of the exception.

Testing Done: Existing unit tests and added a new
test

Signed-off-by: Andon Andonov <[email protected]>
  • Loading branch information
doks5 committed Aug 24, 2021
1 parent 6c8fe4c commit 7e5706c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from taurus.vdk.control.utils.cli_utils import OutputFormat
from taurus_datajob_api import DataJobExecution
from taurus_datajob_api import DataJobExecutionRequest
from taurus.vdk.control.exception.vdk_exception import VDKException

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -56,12 +57,21 @@ def start(self, name: str, team: str, output: OutputFormat):
started_by=f"vdk-control-cli", args={}
)
log.debug(f"Starting job with request {execution_request}")
_, _, headers = self.execution_api.data_job_execution_start_with_http_info(
team_name=team,
job_name=name,
deployment_id="production", # TODO
data_job_execution_request=execution_request,
)

try:
_, _, headers = self.execution_api.data_job_execution_start_with_http_info(
team_name=team,
job_name=name,
deployment_id="production", # TODO
data_job_execution_request=execution_request,
)
except Exception as e:
raise VDKException(
what="An exception occurred while trying to execute the job.",
why=f"The exception was: {e}",
consequence="The data job may not be executed in the cloud.",
countermeasure="Check exception message and try fixing the error.",
)
log.debug(f"Received headers: {headers}")

location = headers["Location"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,13 @@ def test_execute_with_empty_url(httpserver: PluginHTTPServer, tmpdir: LocalPath)
result.exit_code == 2
), f"result exit code is not 2, result output: {result.output}, exc: {result.exc_info}"
assert "what" in result.output and "why" in result.output


def test_execute_with_exception(httpserver: PluginHTTPServer, tmpdir:LocalPath):
runner = CliRunner()
result = runner.invoke(execute, ["--start", "-n", "job_name", "-t", "team_name", "-u", "localhost"])

assert (
result.exit_code == 2
), f"result exit code is not 2, result output: {result.output}, exc: {result.exc_info}"
assert "what" in result.output and "why" in result.output

0 comments on commit 7e5706c

Please sign in to comment.