From ae9f25fe9490ba43339ca04e45b87905f7c2a049 Mon Sep 17 00:00:00 2001 From: Max P Date: Thu, 22 Aug 2024 23:17:54 +0200 Subject: [PATCH] feat: Add new Error `InitializationError` to reflect errors during initialization of a dependency --- src/interfaces/Exceptions.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/interfaces/Exceptions.ts b/src/interfaces/Exceptions.ts index efe6d30..af4c4c8 100644 --- a/src/interfaces/Exceptions.ts +++ b/src/interfaces/Exceptions.ts @@ -37,7 +37,6 @@ export class DependencyResolutionError extends TSinjexError { export class InjectorError extends TSinjexError { /** * Creates a new instance of {@link InjectorError} - * @param message **The error message** * @param identifier **The identifier of the dependency** * @param originalError **The original error that caused the injection error** */ @@ -65,3 +64,21 @@ export class NoInstantiationMethodError extends TSinjexError { this.name = 'TSinjexNoInstantiationMethodError'; } } + +/** + * Error class for errors during the initialization of a dependency in {@link ITSinjex}. + * @see {@link ITSinjex.inject} + */ +export class InitializationError extends TSinjexError { + /** + * Creates a new instance of {@link InitializationError} + * @param identifier **The identifier of the dependency** + * @param originalError **The original error that caused the initialization error** + */ + constructor(identifier: Identifier, originalError?: Error) { + super( + `Error initializing dependency ${identifier.toString()} with error: "${originalError}"`, + ); + this.name = 'TSinjexInitializationError'; + } +}