Skip to content

fix: parse SHIP messages correctly in live TCP and logtail sources - #1

Merged
uhl merged 1 commit into
uhl:mainfrom
MagdyAboKhedrCT:fix/live-ship-message-parsing
Apr 23, 2026
Merged

uhl merged 1 commit into
uhl:mainfrom
MagdyAboKhedrCT:fix/live-ship-message-parsing

Conversation

@MagdyAboKhedrCT

Copy link
Copy Markdown
Contributor

Problem

During live capture (TCP log server and log tail sources), SHIP-level messages such as connectionHello, messageProtocolHandshake, accessMethods, and connectionClose were not being parsed correctly.

Both source_tcp.go and source_logtail.go hardcoded ShipMsgType: ShipMsgTypeData on every incoming message and exclusively called ParseSpineFromJSON to decode the payload.

ParseSpineFromJSON only succeeds when the top-level JSON key is "datagram" — the bare SPINE format logged by eebus-go. SHIP-level messages have different top-level keys, so they always fell through to the error branch and were emitted with the wrong type and a misleading ParseError: "could not parse SPINE datagram from log line".

SPINE data messages worked correctly because eebus-go primarily logs bare {"datagram":{...}} payloads, which ParseSpineFromJSON handles fine.

Solution

Removed the hardcoded ShipMsgType from message initialization. The parsing logic now follows a two-step fallback:

  1. Try ParseSpineFromJSON — if it succeeds, set ShipMsgType to ShipMsgTypeData
  2. If it returns nil, fall back to ParseShipFromJSON, which correctly classifies all SHIP message types and still extracts any embedded SPINE payload when present
  3. Only if both fail is the message emitted with ShipMsgTypeUnknown and a parse error

This mirrors the approach already used correctly in ImportEEBusHubLogFile in store/logimport.go.

Files Changed

  • internal/capture/source_logtail.go — fixed processLine
  • internal/capture/source_tcp.go — fixed emitMessage

@uhl
uhl merged commit b3fc248 into uhl:main Apr 23, 2026
8 checks passed
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