Skip to content

Commit 7ff10f7

Browse files
authored
SNOW-2021431 error codes handle cursor errors (#2183)
1 parent 59d491f commit 7ff10f7

File tree

10 files changed

+306
-3
lines changed

10 files changed

+306
-3
lines changed

src/snowflake/cli/_plugins/helpers/snowsl_vars_reader.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@
8989
"Suggested": "PRIVATE_KEY_PASSPHRASE",
9090
"Additional info": "https://docs.snowflake.com/en/developer-guide/snowflake-cli/connecting/configure-connections",
9191
},
92+
"EXIT_ON_ERROR": {
93+
"Found": "EXIT_ON_ERROR",
94+
"Suggested": "SNOWFLAKE_ENHANCED_EXIT_CODES",
95+
"Additional info": "https://docs.snowflake.com/en/developer-guide/snowflake-cli/sql/execute-sql",
96+
},
9297
}
9398

9499

src/snowflake/cli/api/commands/flags.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ def _diag_log_allowlist_path_callback(path: str):
379379
is_flag=True,
380380
rich_help_panel=_CLI_BEHAVIOUR,
381381
is_eager=True,
382+
envvar="SNOWFLAKE_ENHANCED_EXIT_CODES",
382383
)
383384

384385

src/snowflake/cli/api/commands/snow_typer.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@
3131
ExecutionStatus,
3232
)
3333
from snowflake.cli.api.commands.flags import DEFAULT_CONTEXT_SETTINGS
34-
from snowflake.cli.api.exceptions import CommandReturnTypeError
34+
from snowflake.cli.api.exceptions import (
35+
BaseCliError,
36+
CliArgumentError,
37+
CliError,
38+
CliSqlError,
39+
CommandReturnTypeError,
40+
)
3541
from snowflake.cli.api.output.types import CommandResult
3642
from snowflake.cli.api.sanitizers import sanitize_for_terminal
3743
from snowflake.cli.api.sql_execution import SqlExecutionMixin
@@ -168,8 +174,20 @@ def exception_handler(exception: Exception, execution: ExecutionMetadata):
168174

169175
log.debug("Executing command exception callback")
170176
log_command_execution_error(exception, execution)
177+
exception = SnowTyper._cli_base_exception_migration_dispatcher(exception)
178+
return exception
179+
180+
@staticmethod
181+
def _cli_base_exception_migration_dispatcher(exception):
182+
"""Handler used for dispatching exception until migration completed."""
183+
if isinstance(
184+
exception, (BaseCliError, CliError, CliArgumentError, CliSqlError)
185+
):
186+
return exception
187+
171188
if isinstance(exception, DatabaseError):
172-
return ClickException(exception.msg)
189+
return CliSqlError(exception.msg)
190+
173191
return exception
174192

175193
@staticmethod

tests/__snapshots__/test_help_messages.ambr

Lines changed: 256 additions & 0 deletions
Large diffs are not rendered by default.

tests/api/commands/__snapshots__/test_snow_typer.ambr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@
8888
| to console. |
8989
| --enhanced-exit-codes Differentiate exit error codes |
9090
| based on failure type. |
91+
| [env var: |
92+
| SNOWFLAKE_ENHANCED_EXIT_CODES] |
9193
+------------------------------------------------------------------------------+
9294

9395

@@ -117,6 +119,8 @@
117119
| to console. |
118120
| --enhanced-exit-codes Differentiate exit error codes |
119121
| based on failure type. |
122+
| [env var: |
123+
| SNOWFLAKE_ENHANCED_EXIT_CODES] |
120124
+------------------------------------------------------------------------------+
121125

122126

@@ -168,6 +172,8 @@
168172
| to console. |
169173
| --enhanced-exit-codes Differentiate exit error codes |
170174
| based on failure type. |
175+
| [env var: |
176+
| SNOWFLAKE_ENHANCED_EXIT_CODES] |
171177
+------------------------------------------------------------------------------+
172178

173179

File renamed without changes.

tests/output/__snapshots__/test_silent_output.ambr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@
9393
| to console. |
9494
| --enhanced-exit-codes Differentiate exit error codes |
9595
| based on failure type. |
96+
| [env var: |
97+
| SNOWFLAKE_ENHANCED_EXIT_CODES] |
9698
+------------------------------------------------------------------------------+
9799

98100

tests/sql/__snapshots__/test_sql.ambr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@
106106
| to console. |
107107
| --enhanced-exit-codes Differentiate exit error codes |
108108
| based on failure type. |
109+
| [env var: |
110+
| SNOWFLAKE_ENHANCED_EXIT_CODES] |
109111
+------------------------------------------------------------------------------+
110112

111113

tests/sql/test_sql_enhanced_exit_codes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
pytest.param(
2727
("sql", "-q", "select '&foo'", "--enhanced-exit-codes"),
2828
5,
29-
id="missing variable fails with 1",
29+
id="missing variable fails with 5",
3030
),
3131
),
3232
)

tests_integration/sql/test_sql.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,16 @@ def test_sql_with_variables_from_project(runner, project_directory, template):
217217
)
218218
assert result.exit_code == 0, result.output
219219
assert result.json == [{"VAR": "Knights of Nii"}]
220+
221+
222+
@pytest.mark.integration
223+
def test_sql_ec(runner):
224+
result = runner.invoke_with_connection(
225+
[
226+
"sql",
227+
"--enhanced-exit-codes",
228+
"-q",
229+
"select a",
230+
],
231+
)
232+
assert result.exit_code == 5, result

0 commit comments

Comments
 (0)