You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polaris.apache.org by di...@apache.org on 2026/06/18 22:15:20 UTC

(polaris) branch main updated: Use CliError for profile validation errors (#4791)

This is an automated email from the ASF dual-hosted git repository.

dimas-b pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git


The following commit(s) were added to refs/heads/main by this push:
     new 6fe4a3f2fe Use CliError for profile validation errors (#4791)
6fe4a3f2fe is described below

commit 6fe4a3f2fe935e4529b7d3439b1a4398190243b1
Author: Hema Sri Shalini <12...@users.noreply.github.com>
AuthorDate: Fri Jun 19 03:45:16 2026 +0530

    Use CliError for profile validation errors (#4791)
---
 .../python/apache_polaris/cli/command/profiles.py  |  7 ++----
 client/python/tests/test_profiles_command.py       | 26 +++++++++++++++++-----
 2 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/client/python/apache_polaris/cli/command/profiles.py b/client/python/apache_polaris/cli/command/profiles.py
index 97cb070d80..31e09f0a1e 100644
--- a/client/python/apache_polaris/cli/command/profiles.py
+++ b/client/python/apache_polaris/cli/command/profiles.py
@@ -20,7 +20,6 @@
 import json
 
 import os
-import sys
 from dataclasses import dataclass
 from typing import Dict, Optional, List, Any, cast
 
@@ -91,8 +90,7 @@ class ProfilesCommand(Command):
             }
             self._save_profiles(profiles)
         else:
-            print(f"Profile {name} already exists.")
-            sys.exit(1)
+            raise CliError(f"Profile {name} already exists.")
 
     def _get_profile(self, name: str) -> Optional[Dict[str, Any]]:
         profiles = self._load_profiles()
@@ -142,8 +140,7 @@ class ProfilesCommand(Command):
             }
             self._save_profiles(profiles)
         else:
-            print(f"Profile {name} does not exist.")
-            sys.exit(1)
+            raise CliError(f"Profile {name} does not exist.")
 
     def validate(self) -> None:
         if self.profiles_subcommand in {
diff --git a/client/python/tests/test_profiles_command.py b/client/python/tests/test_profiles_command.py
index 8e4470f486..065ec468a8 100644
--- a/client/python/tests/test_profiles_command.py
+++ b/client/python/tests/test_profiles_command.py
@@ -18,7 +18,9 @@
 #
 
 import io
-from unittest.mock import patch, MagicMock, mock_open, ANY
+from unittest.mock import ANY, MagicMock, mock_open, patch
+
+from apache_polaris.cli.exceptions import CliError
 from cli_test_utils import CLITestBase
 
 
@@ -88,15 +90,14 @@ class TestProfilesCommand(CLITestBase):
         new_callable=mock_open,
         read_data='{"dev": {}}',
     )
-    @patch("apache_polaris.cli.command.profiles.sys.exit")
     def test_profile_create_existing_fails(
-        self, mock_exit: MagicMock, mock_file: MagicMock, mock_exists: MagicMock
+        self, mock_file: MagicMock, mock_exists: MagicMock
     ) -> None:
         mock_client = self.build_mock_client()
         mock_exists.return_value = True
-        with patch("sys.stdout", new_callable=io.StringIO):
+
+        with self.assertRaises(CliError):
             self.mock_execute(mock_client, ["profiles", "create", "dev"])
-        mock_exit.assert_called_once_with(1)
 
     @patch("apache_polaris.cli.command.profiles.os.path.exists")
     @patch(
@@ -145,3 +146,18 @@ class TestProfilesCommand(CLITestBase):
             output = mock_stdout.getvalue()
             self.assertIn("Polaris profile dev updated successfully.", output)
         mock_file.assert_called_with(ANY, "w")
+
+    @patch("apache_polaris.cli.command.profiles.os.path.exists")
+    @patch(
+        "apache_polaris.cli.command.profiles.open",
+        new_callable=mock_open,
+        read_data="{}",
+    )
+    def test_profile_update_missing_fails(
+        self, mock_file: MagicMock, mock_exists: MagicMock
+    ) -> None:
+        mock_client = self.build_mock_client()
+        mock_exists.return_value = True
+
+        with self.assertRaises(CliError):
+            self.mock_execute(mock_client, ["profiles", "update", "missing"])
\ No newline at end of file