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:
22
tests/unit/shared/Stubs/ScriptCodeFactoryStub.ts
Normal file
22
tests/unit/shared/Stubs/ScriptCodeFactoryStub.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import type { ScriptCodeFactory } from '@/domain/ScriptCodeFactory';
|
||||
import type { IScriptCode } from '@/domain/IScriptCode';
|
||||
import { ScriptCodeStub } from './ScriptCodeStub';
|
||||
|
||||
export function createScriptCodeFactoryStub(
|
||||
options?: Partial<StubOptions>,
|
||||
): ScriptCodeFactory {
|
||||
let defaultCodePrefix = 'createScriptCodeFactoryStub';
|
||||
if (options?.defaultCodePrefix) {
|
||||
defaultCodePrefix += ` > ${options?.defaultCodePrefix}`;
|
||||
}
|
||||
return (
|
||||
() => options?.scriptCode ?? new ScriptCodeStub()
|
||||
.withExecute(`[${defaultCodePrefix}] default code`)
|
||||
.withRevert(`[${defaultCodePrefix}] revert code`)
|
||||
);
|
||||
}
|
||||
|
||||
interface StubOptions {
|
||||
readonly scriptCode?: IScriptCode;
|
||||
readonly defaultCodePrefix?: string;
|
||||
}
|
||||
Reference in New Issue
Block a user