A JSONL Import Drops the Final Inspection Without a Trailing Newline
Level 2 · node · Data · Final unterminated JSONL record silently omitted
Scenario
A fictional facility inspection service imports JSON Lines (JSONL) text exported by field devices. Each line contains one inspection object, and files may or may not end with a newline. Files with a trailing newline import correctly, but devices that omit the final newline silently lose their last inspection. Trace the controller, import service, line parser, and repository to preserve every record regardless of how the file ends.
Requirements
Parse each nonempty JSONL line as a JSON object and store the records in order. A valid final line must be imported even without an LF terminator. Support both LF and CRLF, ignore blank lines, and return zero for empty input. If the final line contains malformed JSON, propagate the error and avoid writing any records from that import request. Preserve the function signatures, imported count, and repository ordering.
Acceptance criteria
- A single JSONL record terminated by LF is stored correctly.
- Multiple CRLF-delimited records are stored in input order.
- Empty and whitespace-only lines are not stored as records.
- A single valid record without a final LF is still stored.
- The final unterminated record is preserved after earlier terminated lines.
- Empty input stores no records and returns imported 0.
- Malformed JSON on the final line raises an error without partially writing the request.