Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions ui/desktop/src/components/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { Button } from './ui/button';
import { AlertTriangle } from 'lucide-react';
import { errorMessage } from '../utils/conversionUtils';
import { errorMessage, formatErrorForLogging } from '../utils/conversionUtils';
import { trackErrorWithContext, trackEvent, getErrorType } from '../utils/analytics';

function getCurrentPage(): string {
Expand All @@ -10,7 +10,8 @@ function getCurrentPage(): string {

// Capture unhandled promise rejections
window.addEventListener('unhandledrejection', (event) => {
window.electron.logInfo(`[UNHANDLED REJECTION] ${event.reason}`);
const reasonStr = formatErrorForLogging(event.reason);
window.electron.logInfo(`[UNHANDLED REJECTION] ${reasonStr}`);
trackErrorWithContext(event.reason, {
component: 'global',
page: getCurrentPage(),
Expand Down
3 changes: 2 additions & 1 deletion ui/desktop/src/components/settings/chat/GoosehintsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
DialogHeader,
DialogTitle,
} from '../../ui/dialog';
import { errorMessage } from '../../../utils/conversionUtils';

const HelpText = () => (
<div className="text-sm flex-col space-y-4 text-text-muted">
Expand Down Expand Up @@ -39,7 +40,7 @@ const HelpText = () => (

const ErrorDisplay = ({ error }: { error: Error }) => (
<div className="text-sm text-text-muted">
<div className="text-red-600">Error reading .goosehints file: {JSON.stringify(error)}</div>
<div className="text-red-600">Error reading .goosehints file: {errorMessage(error)}</div>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

</div>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,7 @@ import { useModelAndProvider } from '../../../ModelAndProviderContext';
import { AlertTriangle, LogIn } from 'lucide-react';
import { ProviderDetails, removeCustomProvider, configureProviderOauth } from '../../../../api';
import { Button } from '../../../../components/ui/button';

const formatErrorMessage = (error: unknown): string => {
if (error instanceof Error) {
return error.message;
}
if (typeof error === 'string') {
return error;
}
try {
return JSON.stringify(error);
} catch {
return String(error);
}
};
import { errorMessage } from '../../../../utils/conversionUtils';

interface ProviderConfigurationModalProps {
provider: ProviderDetails;
Expand Down Expand Up @@ -87,7 +74,7 @@ export default function ProviderConfigurationModal({
onClose();
}
} catch (err) {
setError(`OAuth login failed: ${formatErrorMessage(err)}`);
setError(`OAuth login failed: ${errorMessage(err)}`);
} finally {
setIsOAuthLoading(false);
}
Expand Down Expand Up @@ -130,7 +117,7 @@ export default function ProviderConfigurationModal({
onClose();
}
} catch (error) {
setError(formatErrorMessage(error));
setError(errorMessage(error));
}
};

Expand Down
6 changes: 3 additions & 3 deletions ui/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { expandTilde } from './utils/pathUtils';
import log from './utils/logger';
import { ensureWinShims } from './utils/winShims';
import { addRecentDir, loadRecentDirs } from './utils/recentDirs';
import { formatAppName, errorMessage } from './utils/conversionUtils';
import { formatAppName, errorMessage, formatErrorForLogging } from './utils/conversionUtils';
import type { Settings } from './utils/settings';
import { defaultKeyboardShortcuts, getKeyboardShortcuts } from './utils/settings';
import * as crypto from 'crypto';
Expand Down Expand Up @@ -1116,12 +1116,12 @@ const handleFatalError = (error: Error) => {
};

process.on('uncaughtException', (error) => {
console.error('Uncaught Exception:', error);
console.error('Uncaught Exception:', formatErrorForLogging(error));
handleFatalError(error);
});

process.on('unhandledRejection', (error) => {
console.error('Unhandled Rejection:', error);
console.error('Unhandled Rejection:', formatErrorForLogging(error));
handleFatalError(error instanceof Error ? error : new Error(String(error)));
});

Expand Down
8 changes: 4 additions & 4 deletions ui/desktop/src/utils/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ export function trackPageView(page: string, referrer?: string): void {
export function trackError(
errorType: string,
options: {
component?: string; // React component name
page?: string; // Current route/page
action?: string; // What user was doing
stackSummary?: string; // Use getStackSummary() to generate
component?: string;
page?: string;
action?: string;
stackSummary?: string;
recoverable?: boolean;
} = {}
): void {
Expand Down
14 changes: 14 additions & 0 deletions ui/desktop/src/utils/conversionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ export function errorMessage(err: Error | unknown, default_value?: string) {
}
}

export function formatErrorForLogging(error: unknown): string {
if (error instanceof Error) {
return `${error.name}: ${error.message}${error.stack ? `\n${error.stack}` : ''}`;
}
if (typeof error === 'object' && error !== null) {
try {
return JSON.stringify(error, null, 2);
} catch {
return String(error);
}
}
return String(error);
}

export async function compressImageDataUrl(dataUrl: string): Promise<string> {
return new Promise((resolve, reject) => {
const img = new globalThis.Image();
Expand Down
Loading