Skip to content

Commit

Permalink
fix(hr): Emit exit code 1 on error
Browse files Browse the repository at this point in the history
  • Loading branch information
rumpelsepp committed Aug 13, 2024
1 parent 923164d commit 54b4749
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/hr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/bats/100-hr.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
Expand Down

0 comments on commit 54b4749

Please sign in to comment.