Skip to content

fix(dwn-server): validate message params before processing + improve error logging#949

Open
LiranCohen wants to merge 1 commit into
mainfrom
fix-dwn-error-logging
Open

fix(dwn-server): validate message params before processing + improve error logging#949
LiranCohen wants to merge 1 commit into
mainfrom
fix-dwn-error-logging

Conversation

@LiranCohen

Copy link
Copy Markdown
Contributor

Summary

The handleDwnProcessMessage handler destructured message from request params at line 27 — outside the try/catch block (which starts at line 30). When a client sends a request with undefined or malformed message, accessing message.descriptor throws a TypeError that:

  1. Bypasses the catch block entirely
  2. Crashes the server process (Virtual machine exited abruptly in Fly.io logs)
  3. Returns an HTTP 500 instead of a JSON-RPC error

Fix

  • Validate message?.descriptor exists before entering the try block. Returns -32602 InvalidParams with a clear message if missing.
  • Improve error logging: serialize error message and stack trace explicitly, since loglevel's log.error('msg', error) doesn't reliably serialize Error objects to stdout.

Root cause

Discovered while investigating -32603 errors during wallet sync. The server was crashing on requests with undefined message params, causing cascading 500s and VM restarts that made the Fly.io DWN appear unreliable. Already deployed to Fly.io for immediate relief.

Test plan

  • Deployed to Fly.io — server no longer crashes on malformed requests
  • Returns proper -32602 error instead of 500/crash
  • Manual: create wallet → no more intermittent 500s from fly.dev

🤖 Generated with Claude Code

…error logging

The processMessage handler destructured `message` from request params
outside the try/catch block. When a client sends a request with
undefined or malformed `message`, accessing `message.descriptor`
throws a TypeError that crashes the server process (VM exits abruptly)
instead of returning a proper JSON-RPC error.

Fixes:
- Validate `message.descriptor` exists before entering the try block,
  returning -32602 InvalidParams if missing
- Improve error logging to serialize the error message and stack trace
  (loglevel's log.error doesn't always serialize Error objects)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
58.8% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

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.

1 participant