.pr_agent_accepted_suggestions - OpenZeppelin/contracts-wizard GitHub Wiki
PR 631 (2025-08-13) |
[possible issue] Add robust error handling
✅ Add robust error handling
Ensure the process exits with a non-zero code if server connection fails to avoid silent failures. Also handle unhandled rejections to prevent the process from hanging without feedback.
packages/mcp/src/cli.ts [1-11]
#!/usr/bin/env node
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { createServer } from './server';
// Start receiving messages on stdin and sending messages on stdout
const transport = new StdioServerTransport();
(async () => {
- const server = createServer();
- await server.connect(transport);
-})();
+ try {
+ const server = createServer();
+ await server.connect(transport);
+ } catch (err) {
+ console.error('Failed to start MCP server:', err);
+ process.exit(1);
+ }
+})().catch((err) => {
+ console.error('Unhandled error starting MCP server:', err);
+ process.exit(1);
+});
+process.on('unhandledRejection', (reason) => {
+ console.error('Unhandled promise rejection:', reason);
+ process.exit(1);
+});
+
Suggestion importance[1-10]: 7
__
Why: The suggestion correctly identifies that the new CLI script lacks error handling, and proposes adding try/catch
and unhandledRejection
handlers, which is a good practice for robust CLI tools.