From 5affc8cb5abf034ad2c1634c8722d712e1f2c331 Mon Sep 17 00:00:00 2001 From: blozano-tt Date: Thu, 29 Jan 2026 21:31:46 +0000 Subject: [PATCH] Fix: Handle empty stdin gracefully in fixit command When stdin is not a TTY (e.g., in CI environments), CodeChecker fixit would attempt to read and parse JSON from stdin. If stdin was empty, this would fail with 'JSON format error on standard input'. This change reads stdin first and only attempts JSON parsing if there is actual content. Empty stdin is now treated as 'no report filter' (reports = None), which is the same behavior as when stdin is a TTY. This allows 'CodeChecker fixit' to work in CI environments without requiring workarounds like piping empty JSON arrays. --- analyzer/codechecker_analyzer/cli/fixit.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/analyzer/codechecker_analyzer/cli/fixit.py b/analyzer/codechecker_analyzer/cli/fixit.py index 9ed9d45b8e..3c92a4b562 100644 --- a/analyzer/codechecker_analyzer/cli/fixit.py +++ b/analyzer/codechecker_analyzer/cli/fixit.py @@ -377,11 +377,15 @@ def main(args): "arriving from standard input.") sys.exit(1) - try: - reports = None if sys.stdin.isatty() else json.loads(sys.stdin.read()) - except json.decoder.JSONDecodeError as ex: - LOG.error("JSON format error on standard input: %s", ex) - sys.exit(1) + reports = None + if not sys.stdin.isatty(): + stdin_data = sys.stdin.read().strip() + if stdin_data: + try: + reports = json.loads(stdin_data) + except json.decoder.JSONDecodeError as ex: + LOG.error("JSON format error on standard input: %s", ex) + sys.exit(1) # "CodeChecker fixit" can be applied on the output of # "CodeChecker cmd diff" command. Earlier this was a simple list of