Skip to content

Commit

Permalink
Capture the AST unparser STDERR on failure (#2978)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-oplaton authored Feb 6, 2025
1 parent 70bacc4 commit 7f6d091
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/snowflake/snowpark/_internal/proto/ast.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
syntax = "proto3";

option java_package = "com.snowflake.snowpark.proto";
option java_outer_classname = "JavaProto";

package ast;

Expand Down
44 changes: 28 additions & 16 deletions tests/ast/ast_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
VALIDATION_QUERY_RECORD = None


class UnparserInvocationError(Exception):
def __init__(self, error_output: str) -> None:
super().__init__(
f"The unparser invocation failed. STDERR contents: \n{error_output}"
)


def render(ast_base64: Union[str, List[str]], unparser_jar: Optional[str]) -> str:
"""Uses the unparser to render the AST."""
assert (
Expand All @@ -38,22 +45,27 @@ def render(ast_base64: Union[str, List[str]], unparser_jar: Optional[str]) -> st
if isinstance(ast_base64, str):
ast_base64 = [ast_base64]

res = subprocess.run(
[
"java",
"-cp",
unparser_jar,
"com.snowflake.snowpark.unparser.UnparserCli",
",".join(
ast_base64
), # base64 strings will not contain , so pass multiple batches comma-separated.
],
capture_output=True,
text=True,
check=True,
)

return res.stdout
try:
res = subprocess.run(
[
"java",
"-cp",
unparser_jar,
"com.snowflake.snowpark.unparser.UnparserCli",
",".join(
ast_base64
), # base64 strings will not contain , so pass multiple batches comma-separated.
],
capture_output=True,
text=True,
check=True,
)
return res.stdout
except subprocess.CalledProcessError as e:
if e.stderr is not None:
raise UnparserInvocationError(e.stderr) from e
raise
return ""


def generate_error_trace_info(python_text, exception=None):
Expand Down

0 comments on commit 7f6d091

Please sign in to comment.