masaori335 commented on code in PR #13810:
URL: https://github.com/apache/trafficserver/pull/13810#discussion_r4203183753


##########
tools/hrw4u/src/common.py:
##########
@@ -238,17 +239,19 @@ def generate_output(
         filename: str,
         args: Any,
         error_collector: ErrorCollector | None = None,
-        extra_kwargs: dict[str, Any] | None = None) -> bool:
-    """Generate and print output based on mode with optional error collection.
+        extra_kwargs: dict[str, Any] | None = None,
+        out: TextIO | None = None) -> bool:
+    """Write the compiled output to `out`, and return True when the input had 
errors.
 
-    Returns True when the input produced errors, so the caller can set the exit
-    status after every input has been processed rather than aborting mid-run.
+    `out` is a parameter so the caller, which owns the destination, can still 
decide
+    whether to keep the bytes.
     """
+    out = sys.stdout if out is None else out
     if args.ast:
         if tree is not None:
-            print(tree.toStringTree(recog=parser_obj))
+            print(tree.toStringTree(recog=parser_obj), file=out)
         elif error_collector and error_collector.has_errors():
-            print("Parse tree not available due to syntax errors.")
+            print("Parse tree not available due to syntax errors.", 
file=sys.stderr)

Review Comment:
   Fixed in 41b32f8e60: the no-tree notice is printed only for --error-format 
plain; structured formats already carry the parse errors. Added a CLI test that 
every stderr line under --ast --error-format json parses as JSON.



-- 
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