Skip to content

Commit

Permalink
feat(core): add hint to unknown dependency error msg
Browse files Browse the repository at this point in the history
  • Loading branch information
micalevisk committed Nov 15, 2022
1 parent 8e3af06 commit 9d2e960
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ describe('Optional factory provider deps', () => {
.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.
Potential solutions:
- Is RootTestModule a valid NestJS module?
- If MISSING_DEP is a provider, is it part of the current RootTestModule?
- If MISSING_DEP is exported from a separate @Module, is that module imported within RootTestModule?
@Module({
Expand Down
19 changes: 15 additions & 4 deletions packages/core/errors/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,31 @@ export const UNKNOWN_DEPENDENCIES_MESSAGE = (
dependencies,
key,
} = unknownDependencyContext;
const moduleName = getModuleName(module) || 'Module';
const moduleName = getModuleName(module);
const dependencyName = getDependencyName(name);

let message = `Nest can't resolve dependencies of the ${type.toString()}`;

const potentialSolutions = `\n
const potentialSolutions =
moduleName !== 'current'
? `\n
Potential solutions:
- Is ${moduleName} a valid NestJS module?
- If ${dependencyName} is a provider, is it part of the current ${moduleName}?
- If ${dependencyName} is exported from a separate @Module, is that module imported within ${moduleName}?
@Module({
imports: [ /* the Module containing ${dependencyName} */ ]
})
`
: `\n
Potential solutions:
- If ${dependencyName} is a provider, is it part of the current Module?
- If ${dependencyName} is exported from a separate @Module, is that module imported within Module?
@Module({
imports: [ /* the Module containing ${dependencyName} */ ]
})
`;

let message = `Nest can't resolve dependencies of the ${type.toString()}`;

if (isNil(index)) {
message += `. Please make sure that the "${key.toString()}" property is available in the current context.${potentialSolutions}`;
return message;
Expand Down
1 change: 1 addition & 0 deletions packages/core/test/errors/test/messages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ describe('Error Messages', () => {
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.
Potential solutions:
- Is TestModule a valid NestJS module?
- If dependency is a provider, is it part of the current TestModule?
- If dependency is exported from a separate @Module, is that module imported within TestModule?
@Module({
Expand Down

0 comments on commit 9d2e960

Please sign in to comment.