refactor(tools): fix empty catches, remove AI slop from code comments

This commit is contained in:
YeonGyu-Kim
2026-04-03 19:17:09 +09:00
parent 3689ecd5b0
commit 22283fca6d
10 changed files with 38 additions and 35 deletions
+1 -2
View File
@@ -20,8 +20,7 @@ describe("isServerInstalled", () => {
afterEach(() => {
try {
rmSync(tempDir, { recursive: true, force: true })
} catch (e) {
// cleanup failed — ignored
} catch {
}
if (process.platform === "win32") {
+20 -8
View File
@@ -1,3 +1,5 @@
import { log } from "../../shared/logger"
type ManagedClientForCleanup = {
client: {
stop: () => Promise<void>;
@@ -22,23 +24,32 @@ export type LspProcessCleanupHandle = {
export function registerLspManagerProcessCleanup(options: ProcessCleanupOptions): LspProcessCleanupHandle {
const handlers: RegisteredHandler[] = [];
// Synchronous cleanup for 'exit' event (cannot await)
const logCleanupError = (phase: string, error: unknown): void => {
log(`[lsp-manager-process-cleanup] ${phase}`, {
error: error instanceof Error ? error.message : String(error),
});
};
const syncCleanup = () => {
for (const [, managed] of options.getClients()) {
try {
// Fire-and-forget during sync exit - process is terminating
void managed.client.stop().catch(() => {});
} catch {}
void managed.client.stop().catch((error) => {
logCleanupError("stop failed during exit cleanup", error);
});
} catch (error) {
logCleanupError("failed to schedule exit cleanup", error);
}
}
options.clearClients();
options.clearCleanupInterval();
};
// Async cleanup for signal handlers - properly await all stops
const asyncCleanup = async () => {
const stopPromises: Promise<void>[] = [];
for (const [, managed] of options.getClients()) {
stopPromises.push(managed.client.stop().catch(() => {}));
stopPromises.push(managed.client.stop().catch((error) => {
logCleanupError("stop failed during signal cleanup", error);
}));
}
await Promise.allSettled(stopPromises);
options.clearClients();
@@ -52,8 +63,9 @@ export function registerLspManagerProcessCleanup(options: ProcessCleanupOptions)
registerHandler("exit", syncCleanup);
// Don't call process.exit() here; other handlers (background-agent manager) handle final exit.
const signalCleanup = () => void asyncCleanup().catch(() => {});
const signalCleanup = () => void asyncCleanup().catch((error) => {
logCleanupError("signal cleanup failed", error);
});
registerHandler("SIGINT", signalCleanup);
registerHandler("SIGTERM", signalCleanup);
if (process.platform === "win32") {
-3
View File
@@ -2,11 +2,9 @@ import { spawn as bunSpawn } from "bun"
import { spawn as nodeSpawn, type ChildProcess } from "node:child_process"
import { existsSync, statSync } from "fs"
import { log } from "../../shared/logger"
// Bun spawn segfaults on Windows (oven-sh/bun#25798) — unfixed as of v1.3.8+
function shouldUseNodeSpawn(): boolean {
return process.platform === "win32"
}
// Prevents segfaults when libuv gets a non-existent cwd (oven-sh/bun#25798)
export function validateCwd(cwd: string): { valid: boolean; error?: string } {
try {
if (!existsSync(cwd)) {
@@ -24,7 +22,6 @@ export function validateCwd(cwd: string): { valid: boolean; error?: string } {
interface StreamReader {
read(): Promise<{ done: boolean; value: Uint8Array | undefined }>
}
// Bridges Bun Subprocess and Node.js ChildProcess under a common API
export interface UnifiedProcess {
stdin: { write(chunk: Uint8Array | string): void }
stdout: { getReader(): StreamReader }