Skip to content

Commit

Permalink
SNOW-1011769: Updating error message for 'spcs image-registry url' wh…
Browse files Browse the repository at this point in the history
…en no repositories found to be more descriptive
  • Loading branch information
sfc-gh-davwang committed Feb 1, 2024
1 parent 367e64c commit f5fae60
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/snowflake/cli/plugins/spcs/image_registry/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
)
9 changes: 5 additions & 4 deletions src/snowflake/cli/plugins/spcs/image_registry/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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])
6 changes: 3 additions & 3 deletions tests/spcs/__snapshots__/test_registry.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -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.
╰──────────────────────────────────────────────────────────────────────────────╯

'''
Expand Down
4 changes: 1 addition & 3 deletions tests/spcs/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions tests_integration/spcs/__snapshots__/test_registry.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -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.
╰──────────────────────────────────────────────────────────────────────────────╯

'''
Expand Down

0 comments on commit f5fae60

Please sign in to comment.