Files
privacy.sexy/tests/unit/shared/Stubs/StubWithObservableMethodCalls.ts
undergroundwires 4212c7b9e0 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.
2024-05-25 13:55:30 +02:00

26 lines
815 B
TypeScript

import { EventSource } from '@/infrastructure/Events/EventSource';
import type { IEventSource } from '@/infrastructure/Events/IEventSource';
import type { FunctionKeys } from '@/TypeHelpers';
export abstract class StubWithObservableMethodCalls<T> {
public readonly callHistory = new Array<MethodCall<T>>();
private readonly notifiableMethodCalls = new EventSource<MethodCall<T>>();
public get methodCalls(): IEventSource<MethodCall<T>> {
return this.notifiableMethodCalls;
}
protected registerMethodCall(name: MethodCall<T>) {
this.callHistory.push(name);
this.notifiableMethodCalls.notify(name);
}
}
export type MethodCall<T> = {
[K in FunctionKeys<T>]: {
readonly methodName: K;
readonly args: T[K] extends (...args: infer A) => unknown ? A : never;
}
}[FunctionKeys<T>];