diff --git a/src/hr/__init__.py b/src/hr/__init__.py index 0816f2557..6eae8c269 100644 --- a/src/hr/__init__.py +++ b/src/hr/__init__.py @@ -87,6 +87,7 @@ def main() -> None: sys.exit(_main()) except (msgspec.DecodeError, msgspec.ValidationError) as e: print(f"invalid file format: {e}", file=sys.stderr) + sys.exit(1) # BrokenPipeError appears when stuff is piped to | head. except (KeyboardInterrupt, BrokenPipeError): pass diff --git a/tests/bats/100-hr.bats b/tests/bats/100-hr.bats index fcd880104..53fe31da5 100644 --- a/tests/bats/100-hr.bats +++ b/tests/bats/100-hr.bats @@ -25,6 +25,10 @@ zstdcat "$BATS_TEST_DIRNAME/testfiles/log-01.json.zst" | awk '{print "<6>" $0}' | hr - } +@test "pipe invalid data" { + run -1 bash -c "echo 'invalid json' | hr -" +} + @test "filter priority" { local additional_line additional_line='{"module": "foo", "data": "I am the line!", "host": "kronos", "datetime":"2020-04-23T15:21:50.620310", "priority": 5, "version": 2}'