Fix composite submission error logging

This commit is contained in:
gpt-engineer-app[bot]
2025-11-05 14:20:56 +00:00
parent e773ca58d1
commit 116eaa2635
2 changed files with 164 additions and 68 deletions

View File

@@ -34,6 +34,7 @@ export const handleError = (
let errorMessage: string;
let stack: string | undefined;
let errorName = 'UnknownError';
let supabaseErrorDetails: Record<string, any> | undefined;
if (error instanceof Error) {
errorMessage = error instanceof AppError
@@ -41,6 +42,15 @@ export const handleError = (
: error.message;
stack = error.stack;
errorName = error.name;
// Check if Error instance has attached Supabase metadata
if ((error as any).supabaseCode) {
supabaseErrorDetails = {
code: (error as any).supabaseCode,
details: (error as any).supabaseDetails,
hint: (error as any).supabaseHint
};
}
} else if (error && typeof error === 'object') {
// Handle Supabase errors (plain objects with message/code/details)
const supabaseError = error as {
@@ -48,13 +58,24 @@ export const handleError = (
code?: string;
details?: string;
hint?: string;
stack?: string;
};
errorMessage = supabaseError.message || 'An unexpected error occurred';
errorName = 'SupabaseError';
// Create synthetic stack trace for Supabase errors to aid debugging
if (supabaseError.code || supabaseError.details || supabaseError.hint) {
// Capture Supabase error details for metadata
supabaseErrorDetails = {
code: supabaseError.code,
details: supabaseError.details,
hint: supabaseError.hint
};
// Try to extract stack from object
if (supabaseError.stack && typeof supabaseError.stack === 'string') {
stack = supabaseError.stack;
} else if (supabaseError.code || supabaseError.details || supabaseError.hint) {
// Create synthetic stack trace for Supabase errors to aid debugging
const stackParts = [
`SupabaseError: ${errorMessage}`,
supabaseError.code ? ` Code: ${supabaseError.code}` : null,
@@ -68,8 +89,12 @@ export const handleError = (
}
} else if (typeof error === 'string') {
errorMessage = error;
// Generate synthetic stack trace for string errors
stack = new Error().stack?.replace(/^Error\n/, `StringError: ${error}\n`);
} else {
errorMessage = 'An unexpected error occurred';
// Generate synthetic stack trace for unknown error types
stack = new Error().stack?.replace(/^Error\n/, `UnknownError: ${String(error)}\n`);
}
// Log to console/monitoring with enhanced debugging
@@ -84,6 +109,7 @@ export const handleError = (
errorConstructor: error?.constructor?.name,
hasStack: !!stack,
isSyntheticStack: !!(error && typeof error === 'object' && !(error instanceof Error) && stack),
supabaseError: supabaseErrorDetails,
});
// Additional debug logging when stack is missing
@@ -114,11 +140,13 @@ export const handleError = (
p_error_stack: stack,
p_user_agent: navigator.userAgent,
p_breadcrumbs: JSON.stringify({
...breadcrumbs,
breadcrumbs,
isRetry: context.metadata?.isRetry || false,
attempt: context.metadata?.attempt,
retriesExhausted: context.metadata?.retriesExhausted || false,
circuitBreakerState: context.metadata?.circuitState,
supabaseError: supabaseErrorDetails,
metadata: context.metadata
}),
p_timezone: envContext.timezone,
p_referrer: document.referrer || undefined,