Improve context for errors thrown by compiler
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.
This commit is contained in:
@@ -2,22 +2,33 @@ import type { CompiledCode } from '@/application/Parser/Script/Compiler/Function
|
||||
import type { FunctionCallCompiler } from '@/application/Parser/Script/Compiler/Function/Call/Compiler/FunctionCallCompiler';
|
||||
import type { ISharedFunctionCollection } from '@/application/Parser/Script/Compiler/Function/ISharedFunctionCollection';
|
||||
import type { FunctionCall } from '@/application/Parser/Script/Compiler/Function/Call/FunctionCall';
|
||||
import { CompiledCodeStub } from './CompiledCodeStub';
|
||||
|
||||
interface IScenario {
|
||||
calls: FunctionCall[];
|
||||
functions: ISharedFunctionCollection;
|
||||
result: CompiledCode;
|
||||
interface FunctionCallCompilationTestScenario {
|
||||
readonly calls: FunctionCall[];
|
||||
readonly functions: ISharedFunctionCollection;
|
||||
readonly result: CompiledCode;
|
||||
}
|
||||
|
||||
export class FunctionCallCompilerStub implements FunctionCallCompiler {
|
||||
public scenarios = new Array<IScenario>();
|
||||
public scenarios = new Array<FunctionCallCompilationTestScenario>();
|
||||
|
||||
private defaultCompiledCode: CompiledCode = new CompiledCodeStub()
|
||||
.withCode(`[${FunctionCallCompilerStub.name}] function code`)
|
||||
.withRevertCode(`[${FunctionCallCompilerStub.name}] function revert code`);
|
||||
|
||||
public setup(
|
||||
calls: FunctionCall[],
|
||||
functions: ISharedFunctionCollection,
|
||||
result: CompiledCode,
|
||||
) {
|
||||
): this {
|
||||
this.scenarios.push({ calls, functions, result });
|
||||
return this;
|
||||
}
|
||||
|
||||
public withDefaultCompiledCode(defaultCompiledCode: CompiledCode): this {
|
||||
this.defaultCompiledCode = defaultCompiledCode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public compileFunctionCalls(
|
||||
@@ -29,10 +40,7 @@ export class FunctionCallCompilerStub implements FunctionCallCompiler {
|
||||
if (predefined) {
|
||||
return predefined.result;
|
||||
}
|
||||
return {
|
||||
code: 'function code [FunctionCallCompilerStub]',
|
||||
revertCode: 'function revert code [FunctionCallCompilerStub]',
|
||||
};
|
||||
return this.defaultCompiledCode;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user