Skip to content

Commit

Permalink
New error message
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ashen committed Dec 6, 2024
1 parent 5661991 commit 7fcbe72
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/snowflake/cli/_plugins/spcs/services/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,10 @@ def logs(
"""
if follow:
if not FeatureFlag.ENABLE_SPCS_LOG_STREAMING.is_enabled():
raise FeatureNotEnabledError("Log Streaming")
raise FeatureNotEnabledError(
"ENABLE_SPCS_LOG_STREAMING",
"Streaming logs from spcs containers is disabled.",
)
if num_lines != DEFAULT_NUM_LINES:
raise IncompatibleParametersError(["--follow", "--num-lines"])
if previous_logs:
Expand Down
9 changes: 7 additions & 2 deletions src/snowflake/cli/api/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,5 +232,10 @@ def __init__(self, show_obj_query: str):


class FeatureNotEnabledError(RuntimeError):
def __init__(self, feature_name: str):
super().__init__(f"The feature '{feature_name}' is not enabled.")
def __init__(self, feature_name: str, custom_message: Optional[str] = None):
base_message = f"Set the following field in your configuration to enable it: '{feature_name}'."
if custom_message:
message = f"{custom_message} {base_message}"
else:
message = base_message
super().__init__(message)
9 changes: 6 additions & 3 deletions tests/spcs/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,12 +623,12 @@ def test_logs_incompatible_flags(mock_is_enabled, mock_execute_query, runner):
"0",
"--follow",
"--num-lines",
"200",
"100",
]
)
assert (
result.exit_code != 0
), "Expected a non-zero exit code due to incompatible parameters"
), "Expected a non-zero exit code due to incompatible flags"
assert "Parameters '--follow' and '--num-lines' are incompatible" in result.output


Expand Down Expand Up @@ -685,7 +685,10 @@ def test_logs_streaming_disabled(mock_is_enabled, runner):
"100",
]
)
assert "The feature 'Log Streaming' is not enabled" in str(exc_info.value)
assert (
"Streaming logs from spcs containers is disabled. Set the following field in your configuration to enable it: 'ENABLE_SPCS_LOG_STREAMING'."
in str(exc_info.value)
)


def test_read_yaml(other_directory):
Expand Down

0 comments on commit 7fcbe72

Please sign in to comment.