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

HyukjinKwon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark-connect-rust.git


The following commit(s) were added to refs/heads/master by this push:
     new 15397863 [SPARK-61587][FOLLOWUP][CONNECT][BUILD] Print the errors of 
rustc when the doc snippet check fails to build the crate
15397863 is described below

commit 1539786365a03090832f760807466584ffe2993b
Author: Hyukjin Kwon <[email protected]>
AuthorDate: Fri Nov 13 09:34:20 2026 +0900

    [SPARK-61587][FOLLOWUP][CONNECT][BUILD] Print the errors of rustc when the 
doc snippet check fails to build the crate
    
    ### What changes were proposed in this pull request?
    
    A follow-up of #580 (SPARK-61587), from spark-0b's review. Since #580, the 
doc snippet check builds `apache-spark-connect` with `cargo build 
--message-format=json`, which prints rustc's errors as JSON on stdout. When the 
build failed, the check printed only stderr, which says no more than "could not 
compile". It now also prints the rendered error messages from the JSON (errors 
only, not warnings).
    
    ### Why are the changes needed?
    
    So that a failure of the docs job shows its cause.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No.
    
    ### How was this patch tested?
    
    - A new unit test, `test_failed_build_prints_the_rendered_errors_of_rustc`: 
`python3 -m unittest discover -s scripts/tests`, 36 tests OK.
    - `ruff check` and `ruff format --check`.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Generated-by: Claude Opus 5.5
    
    This pull request and its description were written by Isaac.
    
    Closes #591 from HyukjinKwon/SPARK-61587-followup3.
    
    Authored-by: Hyukjin Kwon <[email protected]>
    Signed-off-by: Hyukjin Kwon <[email protected]>
---
 scripts/check_doc_snippets.py            |  9 +++++++++
 scripts/tests/test_check_doc_snippets.py | 27 +++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/scripts/check_doc_snippets.py b/scripts/check_doc_snippets.py
index 5c155705..f9de82f1 100644
--- a/scripts/check_doc_snippets.py
+++ b/scripts/check_doc_snippets.py
@@ -127,6 +127,15 @@ def crate_artifacts() -> tuple[Path | None, list[Path]]:
         text=True,
     )
     if r.returncode != 0:
+        # With --message-format=json, cargo prints the errors of rustc on 
stdout, as JSON.
+        for line in r.stdout.splitlines():
+            try:
+                msg = json.loads(line)
+            except ValueError:
+                continue
+            message = msg.get("message") or {}
+            if msg.get("reason") == "compiler-message" and 
message.get("level") == "error":
+                print(message.get("rendered", ""), end="")
         print(r.stderr[-4000:])
         return None, []
     rlib = None
diff --git a/scripts/tests/test_check_doc_snippets.py 
b/scripts/tests/test_check_doc_snippets.py
index ca44d924..04d39993 100644
--- a/scripts/tests/test_check_doc_snippets.py
+++ b/scripts/tests/test_check_doc_snippets.py
@@ -17,7 +17,10 @@
 """Check metadata-only compilation with rustc; no Spark server or crate build 
needed."""
 
 import importlib.util
+import io
+import json
 import shutil
+import subprocess
 import tempfile
 import unittest
 from pathlib import Path
@@ -66,5 +69,29 @@ class CheckDocSnippetsTests(unittest.TestCase):
                 self.assertIn(diagnostic, error)
 
 
+class CrateArtifactsTests(unittest.TestCase):
+    def test_failed_build_prints_the_rendered_errors_of_rustc(self):
+        # cargo prints the errors of rustc as JSON on stdout with 
--message-format=json.
+        error = {
+            "reason": "compiler-message",
+            "message": {"level": "error", "rendered": "error[E0425]: cannot 
find value `x`\n"},
+        }
+        warning = {
+            "reason": "compiler-message",
+            "message": {"level": "warning", "rendered": "warning: unused 
variable\n"},
+        }
+        stdout = "\n".join([json.dumps(warning), json.dumps(error), "not 
json"])
+        failed = subprocess.CompletedProcess([], 101, stdout=stdout, 
stderr="error: build failed")
+        with (
+            patch.object(checker.subprocess, "run", return_value=failed),
+            patch("sys.stdout", new_callable=io.StringIO) as out,
+        ):
+            self.assertEqual(checker.crate_artifacts(), (None, []))
+        printed = out.getvalue()
+        self.assertIn("error[E0425]: cannot find value `x`", printed)
+        self.assertNotIn("unused variable", printed)
+        self.assertIn("error: build failed", printed)
+
+
 if __name__ == "__main__":
     unittest.main()


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to