A development-only overlay for developing React applications with comprehensive error reporting and debugging capabilities.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Advanced error processing utilities for server-side error handling, stack frame analysis, and comprehensive error formatting with source map integration.
Process and format different types of errors with comprehensive stack trace analysis and source mapping.
/**
* Processes and formats errors by type, returning structured error objects
* @param ev - Error event with ID and event data
* @returns Promise resolving to formatted runtime error with frames
*/
function getErrorByType(ev: SupportedErrorEvent): Promise<ReadyRuntimeError>;
interface SupportedErrorEvent {
id: number;
event: BusEvent;
}
interface ReadyRuntimeError {
id: number;
runtime: true;
error: Error;
frames: OriginalStackFrame[];
componentStack?: string[];
}
interface BusEvent {
type: string;
reason?: Error;
message?: string;
frames?: StackFrame[];
componentStack?: string[];
}Usage Examples:
import { getErrorByType } from "@next/react-dev-overlay";
// Process error event
async function handleErrorEvent(errorEvent: SupportedErrorEvent) {
try {
const processedError = await getErrorByType(errorEvent);
console.log('Error ID:', processedError.id);
console.log('Original error:', processedError.error.message);
console.log('Stack frames:', processedError.frames.length);
if (processedError.componentStack) {
console.log('React component stack:', processedError.componentStack);
}
return processedError;
} catch (error) {
console.error('Failed to process error:', error);
}
}
// Create error event
const errorEvent: SupportedErrorEvent = {
id: Date.now(),
event: {
type: 'unhandled-error',
reason: new Error('Something went wrong'),
frames: [], // Parsed stack frames
}
};
const processedError = await getErrorByType(errorEvent);Process individual stack frames and arrays of stack frames with source mapping and error context.
/**
* Processes individual stack frames with source mapping
* @param source - Original stack frame from error
* @param type - Type of server context for processing
* @param errorMessage - Error message for context
* @returns Promise resolving to processed original stack frame
*/
function getOriginalStackFrame(
source: StackFrame,
type: 'server' | 'edge-server' | null,
errorMessage: string
): Promise<OriginalStackFrame>;
/**
* Processes array of stack frames with source mapping
* @param frames - Array of stack frames to process
* @param type - Type of server context for processing
* @param errorMessage - Error message for context
* @returns Promise resolving to array of processed frames
*/
function getOriginalStackFrames(
frames: StackFrame[],
type: 'server' | 'edge-server' | null,
errorMessage: string
): Promise<OriginalStackFrame[]>;
/**
* Extracts source information from stack frames
* @param frame - Stack frame to extract source from
* @returns Source information string
*/
function getFrameSource(frame: StackFrame): string;Usage Examples:
import {
getOriginalStackFrame,
getOriginalStackFrames,
getFrameSource
} from "@next/react-dev-overlay";
// Process single stack frame
async function processSingleFrame(frame: StackFrame) {
const originalFrame = await getOriginalStackFrame(
frame,
'server',
'Database connection failed'
);
console.log('Processed frame:', originalFrame);
return originalFrame;
}
// Process multiple stack frames
async function processAllFrames(frames: StackFrame[]) {
const originalFrames = await getOriginalStackFrames(
frames,
null,
'Client-side error occurred'
);
originalFrames.forEach((frame, index) => {
console.log(`Frame ${index}:`, frame);
});
return originalFrames;
}
// Extract source information
function analyzeFrame(frame: StackFrame) {
const source = getFrameSource(frame);
console.log('Frame source:', source);
return source;
}Create and process server-specific errors with enhanced context and stack trace information.
/**
* Converts stack frames to filesystem paths
* @param frame - Stack frame to convert
* @returns Stack frame with filesystem path
*/
function getFilesystemFrame(frame: StackFrame): StackFrame;
/**
* Determines error source context from error object
* @param error - Error object to analyze
* @returns Error source type or null
*/
function getErrorSource(error: Error): 'server' | 'edge-server' | null;
/**
* Decorates errors with server context information
* @param error - Error object to decorate
* @param type - Type of server context to add
*/
function decorateServerError(error: Error, type: ErrorType): void;
/**
* Creates server errors with proper stack traces and context
* @param error - Original error object
* @param type - Type of error context
* @returns Enhanced error object with server context
*/
function getServerError(error: Error, type: ErrorType): Error;
type ErrorType = 'server' | 'edge-server';Usage Examples:
import {
getFilesystemFrame,
getErrorSource,
decorateServerError,
getServerError
} from "@next/react-dev-overlay";
// Convert to filesystem frame
function convertToFilesystem(frame: StackFrame) {
const filesystemFrame = getFilesystemFrame(frame);
console.log('Filesystem path:', filesystemFrame.file);
return filesystemFrame;
}
// Analyze error source
function analyzeErrorSource(error: Error) {
const source = getErrorSource(error);
switch (source) {
case 'server':
console.log('Server-side error detected');
break;
case 'edge-server':
console.log('Edge server error detected');
break;
default:
console.log('Client-side or unknown error');
}
return source;
}
// Decorate server error
function enhanceServerError(error: Error) {
decorateServerError(error, 'server');
// Error object is now enhanced with server context
throw error;
}
// Create enhanced server error
function createServerError(originalError: Error) {
const serverError = getServerError(originalError, 'server');
console.log('Enhanced server error:', serverError);
return serverError;
}Parse JavaScript stack traces into structured format with comprehensive analysis.
/**
* Parses error stack traces into structured StackFrame objects
* @param stack - Raw stack trace string from error
* @returns Array of parsed and structured stack frames
*/
function parseStack(stack: string): StackFrame[];
interface StackFrame {
file: string | null;
methodName: string | null;
arguments: string[];
lineNumber: number | null;
column: number | null;
}Usage Examples:
import { parseStack } from "@next/react-dev-overlay";
// Parse error stack trace
function analyzeErrorStack(error: Error) {
if (!error.stack) {
console.log('No stack trace available');
return [];
}
const frames = parseStack(error.stack);
console.log(`Parsed ${frames.length} stack frames:`);
frames.forEach((frame, index) => {
console.log(` ${index + 1}. ${frame.methodName || '<anonymous>'}`);
console.log(` File: ${frame.file || 'unknown'}`);
console.log(` Line: ${frame.lineNumber || 'unknown'}`);
console.log(` Column: ${frame.column || 'unknown'}`);
});
return frames;
}
// Filter relevant frames
function getAppFrames(error: Error): StackFrame[] {
const allFrames = parseStack(error.stack || '');
// Filter out node_modules and system frames
return allFrames.filter(frame => {
if (!frame.file) return false;
if (frame.file.includes('node_modules')) return false;
if (frame.file.includes('/internal/')) return false;
return true;
});
}
// Find error origin
function findErrorOrigin(error: Error): StackFrame | null {
const frames = parseStack(error.stack || '');
// Find first frame that's in application code
return frames.find(frame =>
frame.file &&
!frame.file.includes('node_modules') &&
frame.lineNumber !== null
) || null;
}Comprehensive type definitions for different stack frame states and error processing.
type OriginalStackFrame =
| OriginalStackFrameError
| OriginalStackFrameExternal
| OriginalStackFrameInternal;
interface OriginalStackFrameError {
error: true;
reason: string;
external: false;
expanded: false;
sourceStackFrame: StackFrame;
}
interface OriginalStackFrameExternal {
error: false;
external: true;
expanded: boolean;
sourceStackFrame: StackFrame;
}
interface OriginalStackFrameInternal {
error: false;
reason: null;
external: false;
expanded: boolean;
sourceStackFrame: StackFrame;
originalCodeFrame: string | null;
originalStackFrame: StackFrame;
}Complete workflow for processing errors from capture to display:
// Complete error processing workflow
async function processError(error: Error): Promise<ReadyRuntimeError> {
// 1. Parse stack trace
const frames = parseStack(error.stack || '');
// 2. Determine error source
const source = getErrorSource(error);
// 3. Process each frame
const originalFrames = await getOriginalStackFrames(
frames,
source,
error.message
);
// 4. Create processed error
const processedError: ReadyRuntimeError = {
id: Date.now(),
runtime: true,
error: error,
frames: originalFrames,
};
return processedError;
}