fix: improve config validation error handling#174
Open
Zebastjan wants to merge 1 commit intosynthetic-lab:mainfrom
Open
fix: improve config validation error handling#174Zebastjan wants to merge 1 commit intosynthetic-lab:mainfrom
Zebastjan wants to merge 1 commit intosynthetic-lab:mainfrom
Conversation
When configuration validation fails (e.g., invalid MCP server config or JSON5 syntax errors), OctoFriend now provides clear, actionable error messages instead of crashing with a cryptic stack trace. Changes: - Add comprehensive error handling in readConfig() for JSON5 parsing errors - Detect and provide specific guidance for MCP server configuration issues - Add graceful error handling in runMain() to exit cleanly on config errors - Include helpful examples and suggestions in error messages Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
sdjidjev
requested changes
Apr 6, 2026
Contributor
sdjidjev
left a comment
There was a problem hiding this comment.
I like having more clear error messaging, especially as we add more configurability!
Just a note about how to we can clean the MCP servers validation logic
| mcpServers && typeof mcpServers === "object" && Object.keys(mcpServers).length > 0; | ||
|
|
||
| if ( | ||
| hasMcpServers && |
Contributor
There was a problem hiding this comment.
i think this'll be a lot cleaner if we just do:
const mcpServers = raw["mcpServers"];
if (mcpServers && typeof mcpServers === "object") {
const invalidServers: string[] = [];
for (const [name, serverConfig] of Object.entries(mcpServers)) {
try {
McpServerConfigSchema.slice(serverConfig);
} catch {
invalidServers.push(name);
}
}
if (invalidServers.length > 0) {
throw new Error(
`Invalid MCP server configuration in ${filePath}: ${invalidServers.join(", ")}\n\n` +
`Each MCP server must have:\n` +
` - command: string\n` +
` - args: string[] (optional)\n` +
` - env: object (optional)`,
);
}
}
throw new Error(
`Configuration file validation failed: ${filePath}\n\n` +
`Error: ${errorMessage}\n\n` +
`You can reset your config by deleting: ${filePath}`,
);
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #171 - this is a clean version without the unintended batch tool files.
Problem
When OctoFriend encounters configuration errors (e.g., invalid MCP server config or JSON5 syntax errors), it crashes with an unhelpful error message:
Solution
This PR adds comprehensive error handling that:
octofriend initto start fresh)Changes
source/config.ts: Added try-catch blocks for JSON5 parsing and schema validation with detailed error messagessource/cli.tsx: Added graceful error handling inrunMain()to exit cleanly on config errorsTest plan
commandfield)