/** * Router Error Handling Utilities * * Error boundary and not-found boundary handling for RSC Router. * Also includes the shared invokeOnError utility for error callback invocation. */ import type { ReactNode } from "react"; import type { EntryData } from "../server/context"; import type { ResolvedSegment, ErrorInfo, ErrorBoundaryHandler, NotFoundInfo, NotFoundBoundaryHandler, ErrorPhase, OnErrorCallback } from "../types"; /** * Context required to invoke the onError callback. * This is a subset of OnErrorContext that callers must provide. */ export interface InvokeOnErrorContext { request: Request; url: URL; routeKey?: string; params?: Record; segmentId?: string; segmentType?: "layout" | "route" | "parallel" | "loader" | "middleware"; loaderName?: string; middlewareId?: string; actionId?: string; env?: TEnv; isPartial?: boolean; handledByBoundary?: boolean; metadata?: Record; /** Request start time from performance.now() for duration calculation */ requestStartTime?: number; } /** * Invoke the onError callback with comprehensive context. * Catches any errors in the callback itself to prevent masking the original error. * * This is a shared utility used by both the router and RSC handler to ensure * consistent error callback behavior across the codebase. * * @param onError - The onError callback to invoke (may be undefined) * @param error - The error that occurred * @param phase - The phase where the error occurred * @param context - Additional context about the error * @param logPrefix - Prefix for console.error messages (e.g., "Router" or "RSC") */ export declare function invokeOnError(onError: OnErrorCallback | undefined, error: unknown, phase: ErrorPhase, context: InvokeOnErrorContext, logPrefix?: string): void; /** * Find the nearest error boundary by walking up the entry chain * Also checks sibling layouts (orphan layouts) for error boundaries * Returns the first fallback found, or the default error boundary if configured */ export declare function findNearestErrorBoundary(entry: EntryData | null, defaultErrorBoundary?: ReactNode | ErrorBoundaryHandler): ReactNode | ErrorBoundaryHandler | null; /** * Find the nearest notFound boundary by walking up the entry chain * Returns the first fallback found, or the default notFound boundary if configured */ export declare function findNearestNotFoundBoundary(entry: EntryData | null, defaultNotFoundBoundary?: ReactNode | NotFoundBoundaryHandler): ReactNode | NotFoundBoundaryHandler | null; /** * Create ErrorInfo from an error object * Sanitizes error details in production */ export declare function createErrorInfo(error: unknown, segmentId: string, segmentType: ErrorInfo["segmentType"]): ErrorInfo; /** * Create an error segment with the fallback component * Renders the fallback with error info and reset function */ export declare function createErrorSegment(errorInfo: ErrorInfo, fallback: ReactNode | ErrorBoundaryHandler, entry: EntryData, params: Record): ResolvedSegment; /** * Create NotFoundInfo from a DataNotFoundError */ export declare function createNotFoundInfo(error: { message: string; }, segmentId: string, segmentType: NotFoundInfo["segmentType"], pathname?: string): NotFoundInfo; /** * Create a notFound segment with the fallback component * Renders the fallback with not found info */ export declare function createNotFoundSegment(notFoundInfo: NotFoundInfo, fallback: ReactNode | NotFoundBoundaryHandler, entry: EntryData, params: Record): ResolvedSegment; //# sourceMappingURL=error-handling.d.ts.map