diff options
| author | Jacob Richman <[email protected]> | 2025-07-25 17:35:26 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-07-26 00:35:26 +0000 |
| commit | 21fef1620d78f07af01a75b8bbbeeb15798e73ef (patch) | |
| tree | 751591161eb9d65f6d776152dadf8183a39a8179 /packages/cli/src/ui/App.tsx | |
| parent | fb751c542bc935158aaa0d01c0694eb3bb6b2919 (diff) | |
Handle unhandled rejections more gracefully. (#4417)
Co-authored-by: Tommaso Sciortino <[email protected]>
Diffstat (limited to 'packages/cli/src/ui/App.tsx')
| -rw-r--r-- | packages/cli/src/ui/App.tsx | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/packages/cli/src/ui/App.tsx b/packages/cli/src/ui/App.tsx index da01521b..6163ac51 100644 --- a/packages/cli/src/ui/App.tsx +++ b/packages/cli/src/ui/App.tsx @@ -87,6 +87,7 @@ import ansiEscapes from 'ansi-escapes'; import { OverflowProvider } from './contexts/OverflowContext.js'; import { ShowMoreLines } from './components/ShowMoreLines.js'; import { PrivacyNotice } from './privacy/PrivacyNotice.js'; +import { appEvents, AppEvent } from '../utils/events.js'; const CTRL_EXIT_PROMPT_DURATION_MS = 1000; @@ -176,13 +177,38 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => { return unsubscribe; }, []); + useEffect(() => { + const openDebugConsole = () => { + setShowErrorDetails(true); + setConstrainHeight(false); // Make sure the user sees the full message. + }; + appEvents.on(AppEvent.OpenDebugConsole, openDebugConsole); + + const logErrorHandler = (errorMessage: unknown) => { + handleNewMessage({ + type: 'error', + content: String(errorMessage), + count: 1, + }); + }; + appEvents.on(AppEvent.LogError, logErrorHandler); + + return () => { + appEvents.off(AppEvent.OpenDebugConsole, openDebugConsole); + appEvents.off(AppEvent.LogError, logErrorHandler); + }; + }, [handleNewMessage]); + const openPrivacyNotice = useCallback(() => { setShowPrivacyNotice(true); }, []); const initialPromptSubmitted = useRef(false); const errorCount = useMemo( - () => consoleMessages.filter((msg) => msg.type === 'error').length, + () => + consoleMessages + .filter((msg) => msg.type === 'error') + .reduce((total, msg) => total + msg.count, 0), [consoleMessages], ); |
