MCPcopy Create free account
hub / github.com/RtlZeroMemory/Rezi / createErrorAggregator

Function createErrorAggregator

packages/core/src/debug/errorAggregator.ts:138–270  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

136 * Create an error aggregator instance.
137 */
138export function createErrorAggregator(): ErrorAggregator {
139 const errors: Map<string, MutableError> = new Map();
140 const errorOrder: string[] = [];
141 const handlers: Set<ErrorHandler> = new Set();
142 let totalOccurrences = 0;
143
144 function notifyHandlers(error: AggregatedError): void {
145 for (const handler of handlers) {
146 try {
147 handler(error);
148 } catch {
149 // Ignore handler errors
150 }
151 }
152 }
153
154 function toImmutable(error: MutableError): AggregatedError {
155 return {
156 id: error.id,
157 category: error.category,
158 severity: error.severity,
159 code: error.code,
160 message: error.message,
161 sourceFile: error.sourceFile,
162 sourceLine: error.sourceLine,
163 firstOccurrence: error.firstOccurrence,
164 lastOccurrence: error.lastOccurrence,
165 count: error.count,
166 frameIds: [...error.frameIds],
167 };
168 }
169
170 function addError(
171 record: ErrorRecord,
172 category: DebugCategory,
173 severity: DebugSeverity,
174 timestampUs: bigint,
175 ): void {
176 const timestamp = Number(timestampUs) / 1000;
177 const sourceFile = record.sourceFile || undefined;
178 const id = createErrorId(record.errorCode, record.message, sourceFile);
179
180 totalOccurrences++;
181
182 const existing = errors.get(id);
183 if (existing) {
184 // Update existing error
185 existing.lastOccurrence = timestamp;
186 existing.count++;
187 if (existing.frameIds.length < MAX_FRAME_IDS_PER_ERROR) {
188 // Only add if not already present
189 if (!existing.frameIds.includes(record.frameId)) {
190 existing.frameIds.push(record.frameId);
191 }
192 }
193 notifyHandlers(toImmutable(existing));
194 } else {
195 // Create new error

Callers 1

createDebugControllerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected