Skip to content

Comments

fix: add null check for WebSocket subscription params#556

Open
AlexeySamosadov wants to merge 1 commit intoalchemyplatform:masterfrom
AlexeySamosadov:fix/websocket-null-check
Open

fix: add null check for WebSocket subscription params#556
AlexeySamosadov wants to merge 1 commit intoalchemyplatform:masterfrom
AlexeySamosadov:fix/websocket-null-check

Conversation

@AlexeySamosadov
Copy link

Summary

  • Add defensive null check in handleMessage for malformed subscription events
  • Prevents TypeError: Cannot read properties of undefined (reading 'subscription') during WebSocket reconnection

Motivation

Fixes #547 - During WebSocket reconnections, message.params can be undefined causing a crash. The isSubscriptionEvent() type guard only checks that the message is NOT a response, but doesn't validate that params exists.

Changes

File: src/api/alchemy-websocket-provider.ts

Added guard at line 500:

// Guard against malformed subscription events that pass the type guard
// but have missing params during WebSocket reconnection (Issue #547)
if (!message.params || !message.params.subscription) {
  return;
}

Test Plan

  • TypeScript compilation passes
  • All 406 unit tests pass
  • ESLint passes
  • Prettier formatting passes
  • Pre-commit hooks pass

🤖 Generated with Claude Code

Guard against malformed subscription events during WebSocket
reconnection that pass the type guard but have missing params.

Fixes alchemyplatform#547
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.

Error with websocket reconnection

1 participant