Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null provider message isn't specific #10

Closed
reubenfirmin opened this issue Apr 12, 2019 · 4 comments
Closed

Null provider message isn't specific #10

reubenfirmin opened this issue Apr 12, 2019 · 4 comments

Comments

@reubenfirmin
Copy link

I'm testing my module using mocks. I'm not supplying a particular property (somewhere). I get the following error message:

com.google.inject.CreationException: Unable to create injector, see the following errors:

1) Binding to null instances is not allowed. Use toProvider(Providers.of(null)) if this is your intended behaviour.
  at com.authzee.kotlinguice4.internal.KotlinBindingBuilder.toInstance(KotlinBindingBuilder.kt)

1 error

Please ensure you are naming the null property in this message, otherwise it's extremely hard to track down.

@johnlcox
Copy link
Member

There are no implementations of toInstance in kotlin-guice. All toInstance methods that are part of the kotlin-guice API directly delegate to the Guice implementation of toInstance, which does not add the null property name to the errors.

Unless I'm misunderstanding the issue (a Minimal Complete Verifiable Example would help), this seems like something that would need to be changed in Guice

@reubenfirmin
Copy link
Author

Why does it mention a kotlin-guice class (and only that class) in the stack?

You can reproduce this by passing in mocked resources into a module unit test.

@johnlcox
Copy link
Member

It looks like Guice uses the method #getElementSource() to get the calling line for toInstance bindings when there are errors.

It might be possible to get a better error message in this case by adding some more exclusions to the error source inclusions like this: https://github.com/authzee/kotlin-guice/blob/master/kotlin-guice/src/main/kotlin/com/authzee/kotlinguice4/KotlinModule.kt#L58

@johnlcox
Copy link
Member

Fixed by #13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants