Skip to content

fix: add try-catch around JSON.parse to prevent crashes on malformed data#2

Open
Alex647648 wants to merge 1 commit intodimensionalOS:masterfrom
Alex647648:fix/json-parse-error-handling
Open

fix: add try-catch around JSON.parse to prevent crashes on malformed data#2
Alex647648 wants to merge 1 commit intodimensionalOS:masterfrom
Alex647648:fix/json-parse-error-handling

Conversation

@Alex647648
Copy link

Summary

  • Wrap JSON.parse in the callTool TCP data handler with try-catch — malformed lines are now skipped instead of crashing the process
  • Add try-catch to the child process discovery script's inner JSON.parse for the same reason
  • Wrap the outer JSON.parse(result) in discoverToolsSync with a descriptive error message showing the raw output on failure

Motivation

If the DimOS MCP server sends partial, corrupted, or non-JSON data over the TCP stream, the unguarded JSON.parse would throw an unhandled exception and crash the entire plugin host process.

Test plan

  • Send malformed data to the TCP port while the plugin is connected — verify it logs/skips instead of crashing
  • Verify normal tool calls still work end-to-end

…ormed data

The TCP data handler and child process script both called JSON.parse
without error handling. If the MCP server sends malformed or partial
JSON, the process would crash with an unhandled exception. Now
malformed lines are skipped gracefully, and the discovery response
parse gives a clear error message.
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