import { InspectRenderOptions } from './types' type ErrorArgs = InspectRenderOptions & { name: string maxRenders: number } type ErrorNames = 'maxRenders' const defineError = (errorName: ErrorNames, args: Partial) => { switch (errorName) { case 'maxRenders': return `${args.name} is rendering more than ${args.maxRenders}time per ${ (args.throttleInterval ?? 0) / 1000 }second! If you aware of this, you can disable it in the Settings.ts > Performancer. ` } } /** * Thrown by {@link PerformanceService.inspectRender} when a component exceeds its allowed * render budget. The error name is always `'Codeleap:Perf'`, making it easy to distinguish * from application errors in React error boundaries or crash-reporting tools. */ export class PerformanceError extends Error { constructor(errorName: ErrorNames, args: Partial) { super(defineError(errorName, args)) this.name = 'Codeleap:Perf' } }