Skip to content

Commit 6794486

Browse files
authored
[Tech Debt] standardising the error message for required parameter in cli command (#3827)
<!-- REMOVE IRRELEVANT COMMENTS BEFORE CREATING A PULL REQUEST --> ## Changes <!-- Summary of your changes that are easy to understand. Add screenshots when necessary --> ### Linked issues <!-- DOC: Link issue with a keyword: close, closes, closed, fix, fixes, fixed, resolve, resolves, resolved. See https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword --> Resolves #2740 ### Functionality - [ ] modified existing command: `databricks labs ucx ...` ### Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [ ] added unit tests
1 parent d0bcfc5 commit 6794486

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/databricks/labs/ucx/cli.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ def update_migration_progress(
255255
def repair_run(w: WorkspaceClient, step):
256256
"""Repair Run the Failed Job"""
257257
if not step:
258-
raise KeyError("You did not specify --step")
258+
logger.error("--step is a required parameter")
259+
return
259260
ctx = WorkspaceContext(w)
260261
logger.info(f"Repair Running {step} Job")
261262
ctx.deployed_workflows.repair_run(step)
@@ -313,10 +314,12 @@ def move(
313314
"""move a uc table/tables from one schema to another schema in same or different catalog"""
314315
logger.info("Running move command")
315316
if from_catalog == "" or to_catalog == "":
316-
logger.error("Please enter from_catalog and to_catalog details")
317+
logger.error("--from_catalog and --to_catalog are required parameter")
317318
return
318319
if from_schema == "" or to_schema == "" or from_table == "":
319-
logger.error("Please enter from_schema, to_schema and from_table (enter * for migrating all tables) details.")
320+
logger.error(
321+
"--from_schema, --to_schema and --from_table (enter * for migrating all tables) are required parameter."
322+
)
320323
return
321324
if from_catalog == to_catalog and from_schema == to_schema:
322325
logger.error("please select a different schema or catalog to migrate to")
@@ -342,10 +345,12 @@ def alias(
342345
):
343346
"""move a uc table/tables from one schema to another schema in same or different catalog"""
344347
if from_catalog == "" or to_catalog == "":
345-
logger.error("Please enter from_catalog and to_catalog details")
348+
logger.error("--from_catalog and --to_catalog are required parameter")
346349
return
347350
if from_schema == "" or to_schema == "" or from_table == "":
348-
logger.error("Please enter from_schema, to_schema and from_table (enter * for migrating all tables) details.")
351+
logger.error(
352+
"--from_schema, --to_schema and --from_table (enter * for migrating all tables) are required parameter."
353+
)
349354
return
350355
if from_catalog == to_catalog and from_schema == to_schema:
351356
logger.error("please select a different schema or catalog to migrate to")

tests/unit/test_cli.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,9 @@ def test_repair_run(ws):
414414
ws.jobs.list_runs.assert_called_once()
415415

416416

417-
def test_no_step_in_repair_run(ws):
418-
with pytest.raises(KeyError):
419-
repair_run(ws, "")
417+
def test_no_step_in_repair_run(ws, caplog):
418+
repair_run(ws, "")
419+
assert '--step is a required parameter' in caplog.messages
420420

421421

422422
def test_revert_migrated_tables(ws, caplog):
@@ -440,7 +440,7 @@ def test_move_no_catalog(ws, caplog):
440440
prompts = MockPrompts({})
441441
move(ws, prompts, "", "", "", "", "")
442442

443-
assert 'Please enter from_catalog and to_catalog details' in caplog.messages
443+
assert '--from_catalog and --to_catalog are required parameter' in caplog.messages
444444

445445

446446
def test_move_same_schema(ws, caplog):
@@ -455,7 +455,7 @@ def test_move_no_schema(ws, caplog):
455455
move(ws, prompts, "SrcCat", "", "*", "TgtCat", "")
456456

457457
assert (
458-
'Please enter from_schema, to_schema and from_table (enter * for migrating all tables) details.'
458+
'--from_schema, --to_schema and --from_table (enter * for migrating all tables) are required parameter.'
459459
in caplog.messages
460460
)
461461

@@ -477,7 +477,7 @@ def test_move_aborted_via_prompt(ws):
477477
def test_alias_no_catalog(ws, caplog):
478478
alias(ws, "", "", "", "", "")
479479

480-
assert "Please enter from_catalog and to_catalog details" in caplog.messages
480+
assert "--from_catalog and --to_catalog are required parameter" in caplog.messages
481481

482482

483483
def test_alias_same_schema(ws, caplog):
@@ -490,7 +490,7 @@ def test_alias_no_schema(ws, caplog):
490490
alias(ws, "SrcCat", "", "*", "TgtCat", "")
491491

492492
assert (
493-
'Please enter from_schema, to_schema and from_table (enter * for migrating all tables) details.'
493+
'--from_schema, --to_schema and --from_table (enter * for migrating all tables) are required parameter.'
494494
in caplog.messages
495495
)
496496

0 commit comments

Comments
 (0)