Copilot commented on code in PR #64586:
URL: https://github.com/apache/airflow/pull/64586#discussion_r3025319720


##########
airflow-ctl/src/airflowctl/api/client.py:
##########
@@ -227,9 +227,17 @@ def load(self) -> Credentials:
                     debug_creds_path = os.path.join(
                         default_config_dir, 
f"debug_creds_{self.input_cli_config_file}"
                     )
-                    with open(debug_creds_path) as df:
-                        debug_credentials = json.load(df)
-                        self.api_token = 
debug_credentials.get(f"api_token_{self.api_environment}")
+                    try:
+                        with open(debug_creds_path) as df:
+                            debug_credentials = json.load(df)
+                            self.api_token = 
debug_credentials.get(f"api_token_{self.api_environment}")
+                    except FileNotFoundError as e:
+                        if self.client_kind == ClientKind.CLI:
+                            raise AirflowCtlCredentialNotFoundException(
+                                f"Debug credentials file not found: 
{debug_creds_path}. "
+                                "Set AIRFLOW_CLI_DEBUG_MODE=false or login in 
debug mode first."

Review Comment:
   Minor grammar in the new exception message: “login in debug mode” should be 
“log in (in) debug mode” (or similar). Since this is user-facing, please adjust 
the wording for clarity.
   ```suggestion
                                   "Set AIRFLOW_CLI_DEBUG_MODE=false or log in 
with debug mode enabled first."
   ```



##########
airflow-ctl/tests/airflow_ctl/api/test_client.py:
##########
@@ -376,3 +379,16 @@ def test_retry_handling_ok(self):
             response = client.get("http://error";)
             assert response.status_code == 200
             assert len(responses) == 1
+
+    def test_debug_mode_missing_debug_creds_reports_correct_error(self, 
monkeypatch, tmp_path):
+        monkeypatch.setenv("AIRFLOW_HOME", str(tmp_path))
+        monkeypatch.setenv("AIRFLOW_CLI_DEBUG_MODE", "true")
+        monkeypatch.setenv("AIRFLOW_CLI_ENVIRONMENT", "TEST_DEBUG")
+
+        config_path = tmp_path / "TEST_DEBUG.json"
+        config_path.write_text(json.dumps({"api_url": 
"http://localhost:8080"}), encoding="utf-8")
+        # 不建立 debug_creds_TEST_DEBUG.json,模擬缺檔

Review Comment:
   The inline comment is not in English. This test module’s existing 
comments/docstrings are in English, so please rewrite this comment in English 
to match the repository’s conventions.
   ```suggestion
           # Intentionally do not create debug_creds_TEST_DEBUG.json to 
simulate a missing file
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to