From f5fae60f30e3eea9aea81b2ffc74805bd8edc404 Mon Sep 17 00:00:00 2001 From: David Wang Date: Wed, 31 Jan 2024 16:43:13 -0800 Subject: [PATCH] SNOW-1011769: Updating error message for 'spcs image-registry url' when no repositories found to be more descriptive --- .../cli/plugins/spcs/image_registry/commands.py | 2 +- src/snowflake/cli/plugins/spcs/image_registry/manager.py | 9 +++++---- tests/spcs/__snapshots__/test_registry.ambr | 6 +++--- tests/spcs/test_registry.py | 4 +--- tests_integration/spcs/__snapshots__/test_registry.ambr | 6 +++--- 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/snowflake/cli/plugins/spcs/image_registry/commands.py b/src/snowflake/cli/plugins/spcs/image_registry/commands.py index 1078793d93..cf29238144 100644 --- a/src/snowflake/cli/plugins/spcs/image_registry/commands.py +++ b/src/snowflake/cli/plugins/spcs/image_registry/commands.py @@ -36,5 +36,5 @@ def url(**options) -> MessageResult: return MessageResult(RegistryManager().get_registry_url()) except NoRepositoriesViewableError: raise ClickException( - "Current role does not have permission to view any repositories. Please switch to a role with view access to at least one repository before retrieving registry URL." + "Current role cannot view any image repositories. Please ensure that at least one repository exists in your image registry and use a role with read access to at least one image repository before retrieving registry URL." ) diff --git a/src/snowflake/cli/plugins/spcs/image_registry/manager.py b/src/snowflake/cli/plugins/spcs/image_registry/manager.py index ebc419941f..1c707ec8dd 100644 --- a/src/snowflake/cli/plugins/spcs/image_registry/manager.py +++ b/src/snowflake/cli/plugins/spcs/image_registry/manager.py @@ -9,7 +9,10 @@ class NoRepositoriesViewableError(ClickException): - pass + def __init__( + self, msg: str = "Current role does not have view access to any repositories" + ): + super().__init__(msg) class RegistryManager(SqlExecutionMixin): @@ -56,9 +59,7 @@ def get_registry_url(self): result_set = self._execute_query(repositories_query, cursor_class=DictCursor) results = result_set.fetchall() if len(results) == 0: - raise NoRepositoriesViewableError( - "Current role does not have view access to any repositories" - ) + raise NoRepositoriesViewableError() sample_repository_url = results[0]["repository_url"] return "/".join(sample_repository_url.split("/")[:-3]) diff --git a/tests/spcs/__snapshots__/test_registry.ambr b/tests/spcs/__snapshots__/test_registry.ambr index 8d8c350a93..b9d168cf38 100644 --- a/tests/spcs/__snapshots__/test_registry.ambr +++ b/tests/spcs/__snapshots__/test_registry.ambr @@ -2,9 +2,9 @@ # name: test_get_registry_url_no_repositories_cli ''' ╭─ Error ──────────────────────────────────────────────────────────────────────╮ - │ Current role does not have permission to view any repositories. Please │ - │ switch to a role with view access to at least one repository before │ - │ retrieving registry URL. │ + │ Current role cannot view any image repositories. Please ensure that at least │ + │ one repository exists in your image registry and use a role with read access │ + │ to at least one image repository before retrieving registry URL. │ ╰──────────────────────────────────────────────────────────────────────────────╯ ''' diff --git a/tests/spcs/test_registry.py b/tests/spcs/test_registry.py index 37797bc9e3..058a95f5e6 100644 --- a/tests/spcs/test_registry.py +++ b/tests/spcs/test_registry.py @@ -90,9 +90,7 @@ def test_get_registry_url_no_repositories(mock_execute, mock_conn, mock_cursor): "snowflake.cli.plugins.spcs.image_registry.manager.RegistryManager.get_registry_url" ) def test_get_registry_url_no_repositories_cli(mock_get_registry_url, runner, snapshot): - mock_get_registry_url.side_effect = NoRepositoriesViewableError( - "Current role does not have view access to any repositories" - ) + mock_get_registry_url.side_effect = NoRepositoriesViewableError() result = runner.invoke(["spcs", "image-registry", "url"]) assert result.exit_code == 1, result.output assert result.output == snapshot diff --git a/tests_integration/spcs/__snapshots__/test_registry.ambr b/tests_integration/spcs/__snapshots__/test_registry.ambr index 029626aaba..a5ddc2aeed 100644 --- a/tests_integration/spcs/__snapshots__/test_registry.ambr +++ b/tests_integration/spcs/__snapshots__/test_registry.ambr @@ -2,9 +2,9 @@ # name: test_get_registry_url ''' ╭─ Error ──────────────────────────────────────────────────────────────────────╮ - │ Current role does not have permission to view any repositories. Please │ - │ switch to a role with view access to at least one repository before │ - │ retrieving registry URL. │ + │ Current role cannot view any image repositories. Please ensure that at least │ + │ one repository exists in your image registry and use a role with read access │ + │ to at least one image repository before retrieving registry URL. │ ╰──────────────────────────────────────────────────────────────────────────────╯ '''