Skip to content

Comments

fix: partial line handling in docker events listener#8

Merged
skyrpex merged 8 commits intomainfrom
partial-line-handling-in-docker-events-listener
Sep 3, 2025
Merged

fix: partial line handling in docker events listener#8
skyrpex merged 8 commits intomainfrom
partial-line-handling-in-docker-events-listener

Conversation

@skyrpex
Copy link
Collaborator

@skyrpex skyrpex commented Sep 2, 2025

Improves the handling of stdout data from the docker events process by buffering incomplete lines and only processing complete lines. This prevents errors when event data arrives in chunks that do not align with line boundaries.

@skyrpex skyrpex requested a review from tiurin September 2, 2025 15:11
@skyrpex skyrpex changed the base branch from main to fix-localstack-status-tracker September 2, 2025 15:12
@skyrpex skyrpex changed the base branch from fix-localstack-status-tracker to main September 2, 2025 15:12
Improves the handling of stdout data from the docker events process by buffering incomplete lines and only processing complete lines. This prevents errors when event data arrives in chunks that do not align with line boundaries.
@skyrpex skyrpex force-pushed the partial-line-handling-in-docker-events-listener branch from 3f8328c to 068e717 Compare September 2, 2025 15:12
@skyrpex skyrpex requested a review from anisaoshafi September 2, 2025 15:14
@skyrpex skyrpex marked this pull request as draft September 3, 2025 09:08
@skyrpex
Copy link
Collaborator Author

skyrpex commented Sep 3, 2025

I'll push a commit with a small refactor and some unit tests.

@skyrpex skyrpex marked this pull request as ready for review September 3, 2025 09:37
Copy link
Collaborator

@tiurin tiurin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only have one naming question, otherwise thanks for adding comprehensive test cases!

* Writable stream that buffers data until a newline,
* parses each line as JSON, and emits the parsed object.
*/
export class JsonlStream extends Writable {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: may be it's just for me, I find it hard to read this class name - lowercase l before uppercase S is a bit lost and indeed may look like a typo. :) Moreover, jsonl is not fully standardized yet (both JSONL and JSON Lines are used). How about JsonLineStream for both class and variable name? Again, had to use singular "Line" to avoid double S in JsonLinesStream, but I'm fine with both. WDYT?

Suggested change
export class JsonlStream extends Writable {
export class JsonLineStream extends Writable {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also torn between JsonLineStream and JsonLinesStream, but I believe the latter is more correct. Asked AI for an opinion :)

JsonLinesStream is the better choice.
 • The format is commonly called “JSON Lines” (see: jsonlines.org ↗), not “JSON Line”.
 • The class processes multiple lines, not just a single line.
 • “JsonLinesStream” clearly communicates that it deals with a stream of JSON lines.

So: JsonLinesStream is correct and idiomatic.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does AI have opinion on readability and accidental ligatures? :D

I do, and:

  • I agree that plural is better semantically 👍
  • sS is more difficult to pronounce but easier to read than lS, lowercase s is not lost.

Thanks for updating this!

Copy link
Collaborator Author

@skyrpex skyrpex Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that it's awkward having an sS, although when it comes to pronouncing you can just omit it and say Json Line Stream, I won't notice the difference 😆

assert.deepStrictEqual(callbackCalls[0], { key: "value1" });
});

test("should handle multiple messages in chunks", () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this test case, it is exactly the doubt I had when looking at the code!

@skyrpex skyrpex enabled auto-merge (squash) September 3, 2025 11:37
@skyrpex skyrpex merged commit 6fa9d38 into main Sep 3, 2025
2 checks passed
@skyrpex skyrpex deleted the partial-line-handling-in-docker-events-listener branch September 3, 2025 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants