Skip to content

Commit a2b741a

Browse files
authored
Improved installation failure with actionable message (#840)
1 parent 606dd72 commit a2b741a

File tree

2 files changed

+65
-3
lines changed

2 files changed

+65
-3
lines changed

src/databricks/labs/ucx/install.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,22 @@ def _run_configured(self):
216216
logger.info(msg)
217217

218218
def _create_database(self):
219-
if self._sql_backend is None:
220-
self._sql_backend = StatementExecutionBackend(self._ws, self.current_config.warehouse_id)
221-
deploy_schema(self._sql_backend, self.current_config.inventory_database)
219+
try:
220+
if self._sql_backend is None:
221+
self._sql_backend = StatementExecutionBackend(self._ws, self.current_config.warehouse_id)
222+
deploy_schema(self._sql_backend, self.current_config.inventory_database)
223+
except BadRequest as err:
224+
if "UNRESOLVED_COLUMN.WITH_SUGGESTION" in str(err):
225+
msg = (
226+
"The UCX version is not matching with the installed version."
227+
"Kindly uninstall and reinstall UCX.\n"
228+
"Please Follow the Below Command to uninstall and Install UCX\n"
229+
"UCX Uninstall: databricks labs uninstall ucx.\n"
230+
"UCX Install: databricks labs install ucx"
231+
)
232+
raise BadRequest(msg) from err
233+
msg = f"The UCX Installation Failed while creating database with the error: {err}"
234+
raise BadRequest(msg) from err
222235

223236
def _install_spark_config_for_hms_lineage(self):
224237
hms_lineage = HiveMetastoreLineageEnabler(ws=self._ws)

tests/unit/test_install.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from databricks.labs.blueprint.tui import MockPrompts
1212
from databricks.labs.blueprint.wheels import Wheels, find_project_root
1313
from databricks.sdk.errors import (
14+
BadRequest,
1415
InvalidParameterValue,
1516
NotFound,
1617
OperationFailed,
@@ -1200,3 +1201,51 @@ def test_repair_run_result_state(ws, caplog):
12001201
ws.jobs.list_runs.repair_run = None
12011202
install.repair_run("assessment")
12021203
assert "Please try after sometime" in caplog.text
1204+
1205+
1206+
def test_create_database(ws, mocker, caplog):
1207+
install = WorkspaceInstaller(
1208+
ws,
1209+
sql_backend=None,
1210+
promtps=MockPrompts(
1211+
{
1212+
r".*PRO or SERVERLESS SQL warehouse.*": "1",
1213+
r".*": "",
1214+
}
1215+
),
1216+
)
1217+
mocker.patch(
1218+
"databricks.labs.ucx.install.deploy_schema",
1219+
side_effect=BadRequest(
1220+
"[UNRESOLVED_COLUMN.WITH_SUGGESTION] A column, variable, or "
1221+
"function parameter with name `udf` cannot be resolved"
1222+
),
1223+
)
1224+
mocker.patch("databricks.labs.ucx.framework.crawlers.SqlBackend.execute", return_value=None)
1225+
config_bytes = yaml.dump(WorkspaceConfig(inventory_database="testdb", warehouse_id="123").as_dict()).encode("utf8")
1226+
ws.workspace.download = lambda _: io.BytesIO(config_bytes)
1227+
with pytest.raises(BadRequest) as failure:
1228+
install._create_database()
1229+
1230+
assert "Kindly uninstall and reinstall UCX" in str(failure.value)
1231+
1232+
1233+
def test_create_database_diff_error(ws, mocker, caplog):
1234+
install = WorkspaceInstaller(
1235+
ws,
1236+
sql_backend=MockBackend(),
1237+
promtps=MockPrompts(
1238+
{
1239+
r".*PRO or SERVERLESS SQL warehouse.*": "1",
1240+
r".*": "",
1241+
}
1242+
),
1243+
)
1244+
mocker.patch("databricks.labs.ucx.install.deploy_schema", side_effect=BadRequest("Unknown Error"))
1245+
mocker.patch("databricks.labs.ucx.framework.crawlers.SqlBackend.execute", return_value=None)
1246+
config_bytes = yaml.dump(WorkspaceConfig(inventory_database="testdb", warehouse_id="123").as_dict()).encode("utf8")
1247+
ws.workspace.download = lambda _: io.BytesIO(config_bytes)
1248+
with pytest.raises(BadRequest) as failure:
1249+
install._create_database()
1250+
1251+
assert "The UCX Installation Failed" in str(failure.value)

0 commit comments

Comments
 (0)