This commit introduces a custom error object to provide additional context for errors throwing during parsing and compiling operations, improving troubleshooting. By integrating error context handling, the error messages become more informative and user-friendly, providing sequence of trace with context to aid in troubleshooting. Changes include: - Introduce custom error object that extends errors with contextual information. This replaces previous usages of `AggregateError` which is not displayed well by browsers when logged. - Improve parsing functions to encapsulate error context with more details. - Increase unit test coverage and refactor the related code to be more testable.
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { expect } from 'vitest';
|
|
import type { Constructible } from '@/TypeHelpers';
|
|
import type { ICodeValidationRule } from '@/application/Parser/Script/Validation/ICodeValidationRule';
|
|
import type { ICodeValidator } from '@/application/Parser/Script/Validation/ICodeValidator';
|
|
|
|
export class CodeValidatorStub implements ICodeValidator {
|
|
public callHistory = new Array<{
|
|
code: string,
|
|
rules: readonly ICodeValidationRule[],
|
|
}>();
|
|
|
|
public throwIfInvalid(
|
|
code: string,
|
|
rules: readonly ICodeValidationRule[],
|
|
): void {
|
|
this.callHistory.push({
|
|
code,
|
|
rules: Array.from(rules),
|
|
});
|
|
}
|
|
|
|
public assertHistory(expectation: {
|
|
validatedCodes: readonly (string | undefined)[],
|
|
rules: readonly Constructible<ICodeValidationRule>[],
|
|
}) {
|
|
expect(this.callHistory).to.have.lengthOf(expectation.validatedCodes.length);
|
|
const actualValidatedCodes = this.callHistory.map((args) => args.code);
|
|
expect(actualValidatedCodes.sort()).deep.equal([...expectation.validatedCodes].sort());
|
|
for (const call of this.callHistory) {
|
|
const actualRules = call.rules.map((rule) => rule.constructor);
|
|
expect(actualRules.sort()).to.deep.equal([...expectation.rules].sort());
|
|
}
|
|
}
|
|
}
|