Skip to content

Commit c961d85

Browse files
resolve conflicts
2 parents 276f696 + 20cbbaf commit c961d85

5 files changed

Lines changed: 30 additions & 11 deletions

File tree

lerna.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
22
"lerna": "2.4.0",
3-
"packages": [
4-
"packages/*"
5-
],
3+
"packages": ["packages/*"],
64
"version": "6.0.0-alpha.3"
75
}

packages/core/errors/exceptions/unknown-dependencies.exception.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Module } from '../../injector/module';
55

66
export class UnknownDependenciesException extends RuntimeException {
77
constructor(
8-
type: string,
8+
type: string | symbol,
99
unknownDependencyContext: InjectorDependencyContext,
1010
module?: Module,
1111
) {

packages/core/errors/messages.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { Type } from '@nestjs/common';
2-
import { isNil } from '@nestjs/common/utils/shared.utils';
3-
import { InjectorDependency, InjectorDependencyContext } from '../injector/injector';
2+
import { isNil, isSymbol } from '@nestjs/common/utils/shared.utils';
3+
import {
4+
InjectorDependency,
5+
InjectorDependencyContext,
6+
} from '../injector/injector';
47
import { Module } from '../injector/module';
58

69
// TODO: Replace `any` with `unknown` type when TS 3.0.0 is supported
@@ -18,7 +21,15 @@ const getInstanceName = (instance: unknown) =>
1821
* @param dependency The dependency whichs name should get displayed
1922
*/
2023
const getDependencyName = (dependency: InjectorDependency) =>
21-
getInstanceName(dependency) || dependency || '+';
24+
// use class name
25+
getInstanceName(dependency) ||
26+
// use injection token (symbol)
27+
(isSymbol(dependency) && dependency.toString()) ||
28+
// use string directly
29+
dependency ||
30+
// otherwise
31+
'+';
32+
2233
/**
2334
* Returns the name of the module
2435
* Tries to get the class name. As fallback it returns 'current'.
@@ -28,15 +39,15 @@ const getModuleName = (module: Module) =>
2839
(module && getInstanceName(module.metatype)) || 'current';
2940

3041
export const UNKNOWN_DEPENDENCIES_MESSAGE = (
31-
type: string,
42+
type: string | symbol,
3243
unknownDependencyContext: InjectorDependencyContext,
3344
module: Module,
3445
) => {
3546
const { index, dependencies, key } = unknownDependencyContext;
36-
let message = `Nest can't resolve dependencies of the ${type}`;
47+
let message = `Nest can't resolve dependencies of the ${type.toString()}`;
3748

3849
if (isNil(index)) {
39-
message += `. Please make sure that the "${key}" property is available in the current context.`;
50+
message += `. Please make sure that the "${key.toString()}" property is available in the current context.`;
4051
return message;
4152
}
4253
const dependenciesName = (dependencies || []).map(getDependencyName);

packages/core/injector/injector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export interface InjectorDependencyContext {
4949
/**
5050
* The name of the property key (property-based injection)
5151
*/
52-
key?: string;
52+
key?: string | symbol;
5353
/**
5454
* The name of the function or injection token
5555
*/

packages/core/test/errors/test/messages.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,14 @@ describe('UnknownDependenciesMessage', () => {
4646
myModule.metatype = myMetaType;
4747
expect(new UnknownDependenciesException('CatService', { index, dependencies: ['', 'MY_TOKEN'] }, myModule as Module).message).to.equal(expectedResult);
4848
});
49+
it('should display the symbol name of the provider', () => {
50+
const expectedResult = 'Nest can\'t resolve dependencies of the Symbol(CatProvider) (?). ' +
51+
'Please make sure that the argument at index [0] is available in the current context.';
52+
expect(new UnknownDependenciesException(Symbol('CatProvider'), { index, dependencies: [''] }).message).to.equal(expectedResult);
53+
});
54+
it('should display the symbol dependency of the provider', () => {
55+
const expectedResult = 'Nest can\'t resolve dependencies of the CatProvider (?, Symbol(DogProvider)). ' +
56+
'Please make sure that the argument at index [0] is available in the current context.';
57+
expect(new UnknownDependenciesException('CatProvider', { index, dependencies: ['', Symbol('DogProvider')] }).message).to.equal(expectedResult);
58+
});
4959
});

0 commit comments

Comments
 (0)