Skip to content

Commit

Permalink
refactor: make error messages more descriptive
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Dec 22, 2023
1 parent 91ca351 commit 1f5b563
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ export class ContainerResolver<KnownBindings extends Record<any, any>> {
const error = createError(
`Cannot inject "[class ${binding.name}]" in "[class ${parent.name}]"`
)
error.help = `Container is not able to resolve "${parent.name}" class dependencies`
error.help = `Container is not able to resolve "${parent.name}" class dependencies. Did you mean to use @inject decorator`
return error
}

return createError(
`Cannot construct "[class ${binding.name}]" class. Container is not able to resolve its dependencies`
`Cannot construct "[class ${binding.name}]" class. Container is not able to resolve its dependencies. Did you mean to use @inject decorator`
)
}

Expand Down Expand Up @@ -484,7 +484,7 @@ export class ContainerResolver<KnownBindings extends Record<any, any>> {
throw createError(
`Cannot call "${binding.name}.${String(
method
)}" method. Container is not able to resolve its dependencies`
)}" method. Container is not able to resolve its dependencies. Did you mean to use @inject decorator`
)
}

Expand Down
2 changes: 1 addition & 1 deletion tests/container/call_method.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ test.group('Container | Call method', () => {
const container = new Container()
await assert.rejects(
() => container.call(new UserService(), 'foo'),
'Cannot call "UserService.foo" method. Container is not able to resolve its dependencies'
'Cannot call "UserService.foo" method. Container is not able to resolve its dependencies. Did you mean to use @inject decorator'
)
})

Expand Down
4 changes: 2 additions & 2 deletions tests/container/known_make_class.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ test.group('Container | Make class | Known bindings', () => {
const container = new Container()
await assert.rejects(
() => container.make(UserService),
'Cannot construct "[class UserService]" class. Container is not able to resolve its dependencies'
'Cannot construct "[class UserService]" class. Container is not able to resolve its dependencies. Did you mean to use @inject decorator'
)
})

Expand Down Expand Up @@ -225,7 +225,7 @@ test.group('Container | Make class | Known bindings', () => {
const container = new Container<{ foo: 'bar' }>()
await assert.rejects(
() => container.make(UserService),
'Cannot construct "[class UserService]" class. Container is not able to resolve its dependencies'
'Cannot construct "[class UserService]" class. Container is not able to resolve its dependencies. Did you mean to use @inject decorator'
)
})

Expand Down
8 changes: 3 additions & 5 deletions tests/container/make_class.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ test.group('Container | Make class', () => {
}
})

test('fail when class has dependencies when containerInjections are empty', async ({
assert,
}) => {
test('fail when class has dependencies but containerInjections are empty', async ({ assert }) => {
class UserService {
static containerInjections = {
_constructor: {
Expand All @@ -182,7 +180,7 @@ test.group('Container | Make class', () => {
const container = new Container()
await assert.rejects(
() => container.make(UserService),
'Cannot construct "[class UserService]" class. Container is not able to resolve its dependencies'
'Cannot construct "[class UserService]" class. Container is not able to resolve its dependencies. Did you mean to use @inject decorator'
)
})

Expand Down Expand Up @@ -225,7 +223,7 @@ test.group('Container | Make class', () => {
const container = new Container()
await assert.rejects(
() => container.make(UserService),
'Cannot construct "[class UserService]" class. Container is not able to resolve its dependencies'
'Cannot construct "[class UserService]" class. Container is not able to resolve its dependencies. Did you mean to use @inject decorator'
)
})

Expand Down

0 comments on commit 1f5b563

Please sign in to comment.