Skip to content

Fix stdout/stderr handling to prevent JSON-RPC communication errors #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,11 @@ class GodotServer {

/**
* Log debug messages if debug mode is enabled
* Using stderr instead of stdout to avoid interfering with JSON-RPC communication
*/
private logDebug(message: string): void {
if (DEBUG_MODE) {
console.debug(`[DEBUG] ${message}`);
console.error(`[DEBUG] ${message}`);
}
}

Expand Down Expand Up @@ -332,8 +333,8 @@ class GodotServer {

// If we get here, we couldn't find Godot
this.logDebug(`Warning: Could not find Godot in common locations for ${osPlatform}`);
console.warn(`[SERVER] Could not find Godot in common locations for ${osPlatform}`);
console.warn(`[SERVER] Set GODOT_PATH=/path/to/godot environment variable or pass { godotPath: '/path/to/godot' } in the config to specify the correct path.`);
console.error(`[SERVER] Could not find Godot in common locations for ${osPlatform}`);
console.error(`[SERVER] Set GODOT_PATH=/path/to/godot environment variable or pass { godotPath: '/path/to/godot' } in the config to specify the correct path.`);

if (this.strictPathValidation) {
// In strict mode, throw an error
Expand All @@ -349,8 +350,8 @@ class GodotServer {
}

this.logDebug(`Using default path: ${this.godotPath}, but this may not work.`);
console.warn(`[SERVER] Using default path: ${this.godotPath}, but this may not work.`);
console.warn(`[SERVER] This fallback behavior will be removed in a future version. Set strictPathValidation: true to opt-in to the new behavior.`);
console.error(`[SERVER] Using default path: ${this.godotPath}, but this may not work.`);
console.error(`[SERVER] This fallback behavior will be removed in a future version. Set strictPathValidation: true to opt-in to the new behavior.`);
}
}

Expand Down Expand Up @@ -2171,13 +2172,13 @@ class GodotServer {
process.exit(1);
} else {
// In compatibility mode, warn but continue with the default path
console.warn(`[SERVER] Warning: Using potentially invalid Godot path: ${this.godotPath}`);
console.warn('[SERVER] This may cause issues when executing Godot commands');
console.warn('[SERVER] This fallback behavior will be removed in a future version. Set strictPathValidation: true to opt-in to the new behavior.');
console.error(`[SERVER] Warning: Using potentially invalid Godot path: ${this.godotPath}`);
console.error('[SERVER] This may cause issues when executing Godot commands');
console.error('[SERVER] This fallback behavior will be removed in a future version. Set strictPathValidation: true to opt-in to the new behavior.');
}
}

console.log(`[SERVER] Using Godot at: ${this.godotPath}`);
console.error(`[SERVER] Using Godot at: ${this.godotPath}`);

const transport = new StdioServerTransport();
await this.server.connect(transport);
Expand Down