Skip to content

Commit

Permalink
Merge pull request #10558 from micalevisk/feat/add-solution-on-unknow…
Browse files Browse the repository at this point in the history
…n-dep

feat(core): add hint to unknown dependency error msg
kamilmysliwiec authored Nov 18, 2022

Verified

This commit was signed with the committer’s verified signature.
macmv Neil Macneale V
2 parents 8e3af06 + d3a025c commit 220b098
Showing 4 changed files with 32 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ jobs:
- checkout
- run:
name: Update NPM version
command: 'sudo npm install -g npm@latest'
command: 'sudo npm install -g npm@^8'
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- run:
Original file line number Diff line number Diff line change
@@ -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({
24 changes: 17 additions & 7 deletions packages/core/errors/messages.ts
Original file line number Diff line number Diff line change
@@ -60,20 +60,32 @@ 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 =
// If module's name is well defined
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;
@@ -83,9 +95,7 @@ Potential solutions:

message += ` (`;
message += dependenciesName.join(', ');
message += `). Please make sure that the argument ${dependencyName} at index [${index}] is available in the ${getModuleName(
module,
)} context.`;
message += `). Please make sure that the argument ${dependencyName} at index [${index}] is available in the ${moduleName} context.`;
message += potentialSolutions;

return message;
25 changes: 13 additions & 12 deletions packages/core/test/errors/test/messages.spec.ts
Original file line number Diff line number Diff line change
@@ -18,8 +18,8 @@ describe('Error Messages', () => {
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.
Potential solutions:
- If dependency is a provider, is it part of the current current?
- If dependency is exported from a separate @Module, is that module imported within current?
- If dependency is a provider, is it part of the current Module?
- If dependency is exported from a separate @Module, is that module imported within Module?
@Module({
imports: [ /* the Module containing dependency */ ]
})
@@ -41,8 +41,8 @@ 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 current context.
Potential solutions:
- If dependency is a provider, is it part of the current current?
- If dependency is exported from a separate @Module, is that module imported within current?
- If dependency is a provider, is it part of the current Module?
- If dependency is exported from a separate @Module, is that module imported within Module?
@Module({
imports: [ /* the Module containing dependency */ ]
})
@@ -62,8 +62,8 @@ describe('Error Messages', () => {
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.
Potential solutions:
- If dependency is a provider, is it part of the current current?
- If dependency is exported from a separate @Module, is that module imported within current?
- If dependency is a provider, is it part of the current Module?
- If dependency is exported from a separate @Module, is that module imported within Module?
@Module({
imports: [ /* the Module containing dependency */ ]
})
@@ -83,8 +83,8 @@ describe('Error Messages', () => {
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.
Potential solutions:
- If dependency is a provider, is it part of the current current?
- If dependency is exported from a separate @Module, is that module imported within current?
- If dependency is a provider, is it part of the current Module?
- If dependency is exported from a separate @Module, is that module imported within Module?
@Module({
imports: [ /* the Module containing dependency */ ]
})
@@ -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({
@@ -137,8 +138,8 @@ describe('Error Messages', () => {
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.
Potential solutions:
- If dependency is a provider, is it part of the current current?
- If dependency is exported from a separate @Module, is that module imported within current?
- If dependency is a provider, is it part of the current Module?
- If dependency is exported from a separate @Module, is that module imported within Module?
@Module({
imports: [ /* the Module containing dependency */ ]
})
@@ -158,8 +159,8 @@ describe('Error Messages', () => {
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.
Potential solutions:
- If dependency is a provider, is it part of the current current?
- If dependency is exported from a separate @Module, is that module imported within current?
- If dependency is a provider, is it part of the current Module?
- If dependency is exported from a separate @Module, is that module imported within Module?
@Module({
imports: [ /* the Module containing dependency */ ]
})

0 comments on commit 220b098

Please sign in to comment.