Rocky_Mountain_Vending/.pnpm-store/v10/files/f0/1e55ae904a7eb3aa70b1b2e78cc2d1602a2111efa8fd3a2e5c90aef75e24822985a2552669d892ce857dd26698db57a485e88fd3206b23b57ca26cf6ca77c6
DMleadgen 46d973904b
Initial commit: Rocky Mountain Vending website
Next.js website for Rocky Mountain Vending company featuring:
- Product catalog with Stripe integration
- Service areas and parts pages
- Admin dashboard with Clerk authentication
- SEO optimized pages with JSON-LD structured data

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 16:22:15 -07:00

127 lines
3.8 KiB
Text

import { isInstanceOf } from './is.js';
/**
* Creates exceptions inside `event.exception.values` for errors that are nested on properties based on the `key` parameter.
*/
function applyAggregateErrorsToEvent(
exceptionFromErrorImplementation,
parser,
key,
limit,
event,
hint,
) {
if (!event.exception?.values || !hint || !isInstanceOf(hint.originalException, Error)) {
return;
}
// Generally speaking the last item in `event.exception.values` is the exception originating from the original Error
const originalException =
event.exception.values.length > 0 ? event.exception.values[event.exception.values.length - 1] : undefined;
// We only create exception grouping if there is an exception in the event.
if (originalException) {
event.exception.values = aggregateExceptionsFromError(
exceptionFromErrorImplementation,
parser,
limit,
hint.originalException ,
key,
event.exception.values,
originalException,
0,
);
}
}
function aggregateExceptionsFromError(
exceptionFromErrorImplementation,
parser,
limit,
error,
key,
prevExceptions,
exception,
exceptionId,
) {
if (prevExceptions.length >= limit + 1) {
return prevExceptions;
}
let newExceptions = [...prevExceptions];
// Recursively call this function in order to walk down a chain of errors
if (isInstanceOf(error[key], Error)) {
applyExceptionGroupFieldsForParentException(exception, exceptionId);
const newException = exceptionFromErrorImplementation(parser, error[key]);
const newExceptionId = newExceptions.length;
applyExceptionGroupFieldsForChildException(newException, key, newExceptionId, exceptionId);
newExceptions = aggregateExceptionsFromError(
exceptionFromErrorImplementation,
parser,
limit,
error[key],
key,
[newException, ...newExceptions],
newException,
newExceptionId,
);
}
// This will create exception grouping for AggregateErrors
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError
if (Array.isArray(error.errors)) {
error.errors.forEach((childError, i) => {
if (isInstanceOf(childError, Error)) {
applyExceptionGroupFieldsForParentException(exception, exceptionId);
const newException = exceptionFromErrorImplementation(parser, childError);
const newExceptionId = newExceptions.length;
applyExceptionGroupFieldsForChildException(newException, `errors[${i}]`, newExceptionId, exceptionId);
newExceptions = aggregateExceptionsFromError(
exceptionFromErrorImplementation,
parser,
limit,
childError,
key,
[newException, ...newExceptions],
newException,
newExceptionId,
);
}
});
}
return newExceptions;
}
function applyExceptionGroupFieldsForParentException(exception, exceptionId) {
// Don't know if this default makes sense. The protocol requires us to set these values so we pick *some* default.
exception.mechanism = exception.mechanism || { type: 'generic', handled: true };
exception.mechanism = {
...exception.mechanism,
...(exception.type === 'AggregateError' && { is_exception_group: true }),
exception_id: exceptionId,
};
}
function applyExceptionGroupFieldsForChildException(
exception,
source,
exceptionId,
parentId,
) {
// Don't know if this default makes sense. The protocol requires us to set these values so we pick *some* default.
exception.mechanism = exception.mechanism || { type: 'generic', handled: true };
exception.mechanism = {
...exception.mechanism,
type: 'chained',
source,
exception_id: exceptionId,
parent_id: parentId,
};
}
export { applyAggregateErrorsToEvent };
//# sourceMappingURL=aggregate-errors.js.map