From 53a5728009adf1e91115ee0eb839eafa00262adf Mon Sep 17 00:00:00 2001 From: Jaana Dogan Date: Mon, 21 Apr 2025 12:15:47 -0700 Subject: 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. --- packages/cli/src/gemini.ts | 27 ++++++++++++++------------- packages/cli/src/ui/hooks/useStdin.ts | 10 +++++----- 2 files changed, 19 insertions(+), 18 deletions(-) (limited to 'packages/cli/src') diff --git a/packages/cli/src/gemini.ts b/packages/cli/src/gemini.ts index 60863c6a..97502399 100644 --- a/packages/cli/src/gemini.ts +++ b/packages/cli/src/gemini.ts @@ -54,20 +54,21 @@ process.on('unhandledRejection', (reason, _promise) => { ); console.warn('-----------------------------------------'); console.warn('Reason:', reason); - // No process.exit(1); - } else { - // Log other unexpected unhandled rejections as critical errors - console.error('========================================='); - console.error('CRITICAL: Unhandled Promise Rejection!'); - console.error('========================================='); - console.error('Reason:', reason); - console.error('Stack trace may follow:'); - if (!(reason instanceof Error)) { - console.error(reason); - } - // Exit for genuinely unhandled errors - process.exit(1); + return; + // No process.exit(1); Don't exit. + } + + // Log other unexpected unhandled rejections as critical errors + console.error('========================================='); + console.error('CRITICAL: Unhandled Promise Rejection!'); + console.error('========================================='); + console.error('Reason:', reason); + console.error('Stack trace may follow:'); + if (!(reason instanceof Error)) { + console.error(reason); } + // Exit for genuinely unhandled errors + process.exit(1); }); // --- Global Entry Point --- diff --git a/packages/cli/src/ui/hooks/useStdin.ts b/packages/cli/src/ui/hooks/useStdin.ts index e91b90e6..dc245254 100644 --- a/packages/cli/src/ui/hooks/useStdin.ts +++ b/packages/cli/src/ui/hooks/useStdin.ts @@ -70,13 +70,13 @@ export function usePipedInput(): PipedInputState { stdin.removeListener('error', handleError); stdin.removeListener('end', handleEnd); }; - } else { - // No piped input (running interactively) - setIsLoading(false); - // Optionally set an 'info' state or just let isLoading=false & isPiped=false suffice - // setError('No piped input detected.'); // Maybe don't treat this as an 'error' } + // No piped input (running interactively) + setIsLoading(false); + // Optionally set an 'info' state or just let isLoading=false & isPiped=false suffice + // setError('No piped input detected.'); // Maybe don't treat this as an 'error' + // Intentionally run only once on mount or when stdin theoretically changes }, [stdin, isRawModeSupported, setRawMode /*, exit */]); -- cgit v1.2.3