diff --git a/.npmignore b/.npmignore index caeb37a8..f1310cf3 100644 --- a/.npmignore +++ b/.npmignore @@ -17,6 +17,7 @@ mocha.opts prettier.config.mjs PULL_REQUEST_TEMPLATE.md renovate.json +scripts src temp test diff --git a/CHANGELOG.md b/CHANGELOG.md index f992c3c3..0a376dcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### Changed +- Updated planner with better error description when a binding can not be properly resolved. ### Fixed diff --git a/src/constants/error_msgs.ts b/src/constants/error_msgs.ts index 85bfbf51..6353ad64 100644 --- a/src/constants/error_msgs.ts +++ b/src/constants/error_msgs.ts @@ -9,8 +9,9 @@ export const AMBIGUOUS_MATCH: string = export const CANNOT_UNBIND: string = 'Could not unbind serviceIdentifier:'; export const NOT_REGISTERED: string = 'No matching bindings found for serviceIdentifier:'; -export const MISSING_INJECTABLE_ANNOTATION: string = - 'Missing required @injectable annotation in:'; +export const TRYING_TO_RESOLVE_BINDINGS: (name: string) => string = ( + name: string, +) => `Trying to resolve bindings for "${name}"`; export const UNDEFINED_INJECT_ANNOTATION: (name: string) => string = ( name: string, ) => diff --git a/src/planning/planner.ts b/src/planning/planner.ts index a20bfccf..c3c8bd36 100644 --- a/src/planning/planner.ts +++ b/src/planning/planner.ts @@ -113,6 +113,7 @@ function _getActiveBindings( _validateActiveBindingCount( target.serviceIdentifier, activeBindings, + parentRequest, target, context.container, ); @@ -144,6 +145,7 @@ function _getTargetMetadata( function _validateActiveBindingCount( serviceIdentifier: interfaces.ServiceIdentifier, bindings: interfaces.Binding[], + parentRequest: interfaces.Request | null, target: interfaces.Target, container: interfaces.Container, ): interfaces.Binding[] { @@ -161,6 +163,11 @@ function _validateActiveBindingCount( serviceIdentifierString, getBindings, ); + + if (parentRequest !== null) { + msg += `\n${ERROR_MSGS.TRYING_TO_RESOLVE_BINDINGS(getServiceIdentifierAsString(parentRequest.serviceIdentifier))}`; + } + throw new Error(msg); } diff --git a/test/planning/planner.test.ts b/test/planning/planner.test.ts index 4538e331..b7fb3552 100644 --- a/test/planning/planner.test.ts +++ b/test/planning/planner.test.ts @@ -669,7 +669,8 @@ describe('Planner', () => { }; expect(throwFunction).to.throw( - 'No matching bindings found for serviceIdentifier: Function', + `No matching bindings found for serviceIdentifier: Function +Trying to resolve bindings for "Ninja"`, ); }); });