Skip to content

Commit 70ba868

Browse files
committed
feat(core): add hint to unknown dependency error msg
1 parent 8e3af06 commit 70ba868

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

integration/injector/e2e/optional-factory-provider-dep.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ describe('Optional factory provider deps', () => {
121121
.equal(`Nest can't resolve dependencies of the POSSIBLY_MISSING_DEP (?). Please make sure that the argument MISSING_DEP at index [0] is available in the RootTestModule context.
122122
123123
Potential solutions:
124+
- Is RootTestModule a valid NestJS module?
124125
- If MISSING_DEP is a provider, is it part of the current RootTestModule?
125126
- If MISSING_DEP is exported from a separate @Module, is that module imported within RootTestModule?
126127
@Module({

packages/core/errors/messages.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,30 @@ export const UNKNOWN_DEPENDENCIES_MESSAGE = (
6060
dependencies,
6161
key,
6262
} = unknownDependencyContext;
63-
const moduleName = getModuleName(module) || 'Module';
63+
const moduleName = getModuleName(module) || undefined;
6464
const dependencyName = getDependencyName(name);
6565

66-
let message = `Nest can't resolve dependencies of the ${type.toString()}`;
67-
68-
const potentialSolutions = `\n
66+
const potentialSolutions = moduleName
67+
? `\n
6968
Potential solutions:
69+
- Is ${moduleName} a valid NestJS module?
7070
- If ${dependencyName} is a provider, is it part of the current ${moduleName}?
7171
- If ${dependencyName} is exported from a separate @Module, is that module imported within ${moduleName}?
7272
@Module({
7373
imports: [ /* the Module containing ${dependencyName} */ ]
7474
})
75+
`
76+
: `\n
77+
Potential solutions:
78+
- If ${dependencyName} is a provider, is it part of the current Module?
79+
- If ${dependencyName} is exported from a separate @Module, is that module imported within Module?
80+
@Module({
81+
imports: [ /* the Module containing ${dependencyName} */ ]
82+
})
7583
`;
7684

85+
let message = `Nest can't resolve dependencies of the ${type.toString()}`;
86+
7787
if (isNil(index)) {
7888
message += `. Please make sure that the "${key.toString()}" property is available in the current context.${potentialSolutions}`;
7989
return message;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe('Error Messages', () => {
1818
stringCleaner(`Nest can't resolve dependencies of the CatService (?, CatService). Please make sure that the argument dependency at index [0] is available in the current context.
1919
2020
Potential solutions:
21+
- Is current a valid NestJS module?
2122
- If dependency is a provider, is it part of the current current?
2223
- If dependency is exported from a separate @Module, is that module imported within current?
2324
@Module({
@@ -41,6 +42,7 @@ describe('Error Messages', () => {
4142
stringCleaner(`Nest can't resolve dependencies of the CatService (?, MY_TOKEN). Please make sure that the argument dependency at index [0] is available in the current context.
4243
4344
Potential solutions:
45+
- Is current a valid NestJS module?
4446
- If dependency is a provider, is it part of the current current?
4547
- If dependency is exported from a separate @Module, is that module imported within current?
4648
@Module({
@@ -62,6 +64,7 @@ describe('Error Messages', () => {
6264
stringCleaner(`Nest can't resolve dependencies of the CatService (?, CatFunction). Please make sure that the argument dependency at index [0] is available in the current context.
6365
6466
Potential solutions:
67+
- Is current a valid NestJS module?
6568
- If dependency is a provider, is it part of the current current?
6669
- If dependency is exported from a separate @Module, is that module imported within current?
6770
@Module({
@@ -83,6 +86,7 @@ describe('Error Messages', () => {
8386
stringCleaner(`Nest can't resolve dependencies of the CatService (?, +). Please make sure that the argument dependency at index [0] is available in the current context.
8487
8588
Potential solutions:
89+
- Is current a valid NestJS module?
8690
- If dependency is a provider, is it part of the current current?
8791
- If dependency is exported from a separate @Module, is that module imported within current?
8892
@Module({
@@ -104,6 +108,7 @@ describe('Error Messages', () => {
104108
stringCleaner(`Nest can't resolve dependencies of the CatService (?, MY_TOKEN). Please make sure that the argument dependency at index [0] is available in the TestModule context.
105109
106110
Potential solutions:
111+
- Is TestModule a valid NestJS module?
107112
- If dependency is a provider, is it part of the current TestModule?
108113
- If dependency is exported from a separate @Module, is that module imported within TestModule?
109114
@Module({
@@ -137,6 +142,7 @@ describe('Error Messages', () => {
137142
stringCleaner(`Nest can't resolve dependencies of the Symbol(CatProvider) (?). Please make sure that the argument dependency at index [0] is available in the current context.
138143
139144
Potential solutions:
145+
- Is current a valid NestJS module?
140146
- If dependency is a provider, is it part of the current current?
141147
- If dependency is exported from a separate @Module, is that module imported within current?
142148
@Module({
@@ -158,6 +164,7 @@ describe('Error Messages', () => {
158164
stringCleaner(`Nest can't resolve dependencies of the CatProvider (?, Symbol(DogProvider)). Please make sure that the argument dependency at index [0] is available in the current context.
159165
160166
Potential solutions:
167+
- Is current a valid NestJS module?
161168
- If dependency is a provider, is it part of the current current?
162169
- If dependency is exported from a separate @Module, is that module imported within current?
163170
@Module({

0 commit comments

Comments
 (0)