Copilot commented on code in PR #13810:
URL: https://github.com/apache/trafficserver/pull/13810#discussion_r4203088371
##########
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:
This unconditional plain-text fallback breaks structured diagnostics. With
`--ast --error-format json` and an input for which no tree is built, stderr
contains this sentence followed by the JSON error summary, so it is no longer
the promised one-object-per-input NDJSON stream. Keep the fallback only for
plain mode (structured modes already report the parse errors through their
formatter).
--
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]