diff options
| author | Jaana Dogan <[email protected]> | 2025-04-21 12:15:47 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-04-21 12:15:47 -0700 |
| commit | 53a5728009adf1e91115ee0eb839eafa00262adf (patch) | |
| tree | 2ad9b1a643f55ea22cc19946213f5790a9f2c8ce /packages/server/src/utils/BackgroundTerminalAnalyzer.ts | |
| parent | dea0782c891b2d849cc31c1364b32a9fb9a7a312 (diff) | |
Remove redundant else branches (#86)
Else branches are an anti pattern especially if you can easily return from the previous branch. Over time, else branches cause deep nesting and make code unreadable and unmaintainable. Remove elses where possible.
Diffstat (limited to 'packages/server/src/utils/BackgroundTerminalAnalyzer.ts')
| -rw-r--r-- | packages/server/src/utils/BackgroundTerminalAnalyzer.ts | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/packages/server/src/utils/BackgroundTerminalAnalyzer.ts b/packages/server/src/utils/BackgroundTerminalAnalyzer.ts index 31cd91c6..5ff29997 100644 --- a/packages/server/src/utils/BackgroundTerminalAnalyzer.ts +++ b/packages/server/src/utils/BackgroundTerminalAnalyzer.ts @@ -299,32 +299,31 @@ export class BackgroundTerminalAnalyzer { const { stdout } = await execAsync(command); // Check if the output contains the process information (it will have the image name if found) return stdout.toLowerCase().includes('.exe'); // A simple check, adjust if needed - } else { - // Linux/macOS/Unix-like: Use kill -0 signal - // process.kill sends signal 0 to check existence without killing - process.kill(pid, 0); - return true; // If no error is thrown, process exists } + // Linux/macOS/Unix-like: Use kill -0 signal + // process.kill sends signal 0 to check existence without killing + process.kill(pid, 0); + return true; // If no error is thrown, process exists } catch (error: unknown) { if (isNodeError(error) && error.code === 'ESRCH') { // ESRCH: Standard error code for "No such process" on Unix-like systems return false; - } else if ( + } + if ( process.platform === 'win32' && getErrorMessage(error).includes('No tasks are running') ) { // tasklist specific error when PID doesn't exist return false; - } else { - // Other errors (e.g., EPERM - permission denied) mean we couldn't determine status. - // Re-throwing might be appropriate depending on desired behavior. - // Here, we log it and cautiously return true, assuming it *might* still be running. - console.warn( - `isProcessRunning(${pid}) encountered error: ${getErrorMessage(error)}. Assuming process might still exist.`, - ); - // Or you could throw the error: throw new Error(`Failed to check process status for PID ${pid}: ${error.message}`); - return true; // Cautious assumption } + // Other errors (e.g., EPERM - permission denied) mean we couldn't determine status. + // Re-throwing might be appropriate depending on desired behavior. + // Here, we log it and cautiously return true, assuming it *might* still be running. + console.warn( + `isProcessRunning(${pid}) encountered error: ${getErrorMessage(error)}. Assuming process might still exist.`, + ); + // Or you could throw the error: throw new Error(`Failed to check process status for PID ${pid}: ${error.message}`); + return true; // Cautious assumption } } |
