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.
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import type { IFunctionParameter } from '@/application/Parser/Script/Compiler/Function/Parameter/IFunctionParameter';
|
|
import type { IFunctionParameterCollection } from '@/application/Parser/Script/Compiler/Function/Parameter/IFunctionParameterCollection';
|
|
import { FunctionParameterStub } from './FunctionParameterStub';
|
|
|
|
export class FunctionParameterCollectionStub implements IFunctionParameterCollection {
|
|
private parameters = new Array<IFunctionParameter>();
|
|
|
|
public addParameter(parameter: IFunctionParameter): void {
|
|
this.parameters.push(parameter);
|
|
}
|
|
|
|
public get all(): readonly IFunctionParameter[] {
|
|
return this.parameters;
|
|
}
|
|
|
|
public withParameterName(parameterName: string, isOptional = true) {
|
|
const parameter = new FunctionParameterStub()
|
|
.withName(parameterName)
|
|
.withOptional(isOptional);
|
|
this.addParameter(parameter);
|
|
return this;
|
|
}
|
|
|
|
public withParameterNames(parameterNames: readonly string[], isOptional = true) {
|
|
for (const parameterName of parameterNames) {
|
|
this.withParameterName(parameterName, isOptional);
|
|
}
|
|
return this;
|
|
}
|
|
}
|