Skip to content

Log and reject unknown messageType values in receiveMessage #191

@arasaka-net

Description

@arasaka-net

receiveMessage in src/scripts/p2p.js silently drops any message whose messageType does not match an enumerated case. Add a default branch that logs the offending payload and cover it with a test.

Context
The P2P layer is the trust boundary between the wire and the local board. When a peer sends a message with an unrecognized messageType — because of a version skew, a bug, or a malformed payload — receiveMessage currently falls through the outer switch with no warning, no log, and no banner. The receiving client has no way to know a message was ignored, which produces exactly the kind of silent desync the table should make visible. A bounded fix is to add a default: branch that logs the full message via console.warn and returns, mirroring the existing warnings on missing elements for grab-element, move-element, and ungrab-element. A matching unit test locks the behavior in.

Affected Files

  • src/scripts/p2p.js:124 — Add a default: branch to the outer switch (message.messageType) that logs the full message via console.warn and returns without mutating the DOM.
  • src/scripts/p2p.js:80 — Add a default: branch to the inner switch (message.entityType) inside create-element for the same reason.
  • src/scripts/p2p.test.js — Add tests that assert unknown messageType and unknown entityType values log a warning and do not touch the DOM.

Requirements

  • receiveMessage logs a warning when it receives a message with an unknown messageType.
  • receiveMessage logs a warning when a create-element message carries an unknown entityType.
  • Neither case mutates the DOM or dispatches any CustomEvent.
  • A Vitest test spies on console.warn and verifies both behaviors.
  • npm test and npm run lint pass after the change.

Verification

  • npm test -- src/scripts/p2p.test.js
  • npm run lint
  • grep -n 'default:' src/scripts/p2p.js

Not In Scope

  • Do not introduce a message schema validator or type guards beyond the default: branches.
  • Do not add a protocol version field — that is a separate change.
  • Do not refactor the outer switch into a dispatch table.

Evidence

  • src/scripts/p2p.js:48-124 — Outer switch (message.messageType) has no default: branch; unknown types fall through silently.
  • src/scripts/p2p.js:50-80 — Inner switch (message.entityType) inside create-element has no default: branch; unknown entities are silently ignored.
  • src/scripts/p2p.js:86grab-element already logs receiveMessage: grab-element ignored — no element with id ... — the same warning style should apply to the new default branches.

Arasaka Queue Planning Division.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions