-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Improve error message when "No valid constructors" #9501
Conversation
A more descriptive commit message would be nice 😉 |
@mkurz I improved the commit message with a little more detail |
5ba3a27
to
df6d161
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@renatocaval Actually I included more detail several lines bellow. I've ammended it so that the whole thing is visible in only one line:
Is that ok? Thanks for your time |
Yep, that's perfect. Thanks @fagossa |
…tors" This commit does the following : * List the available constructors while creating a module, when no available constructor is found * Add a new unit test * Add a new utility function in ConstructorUtils
case e => | ||
e.getMessage must contain("(com.typesafe.config.Config, java.lang.String, long)") | ||
e.getMessage must contain("(com.typesafe.config.Config, java.lang.String)") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you got it the other way around.
If we throw such an exception to the users, we are just telling them which constructors we have found on the module they registered.
The actual suggestion was to inform the users that the module has the wrong constructor signature and therefore they need to adapt.
See @kubukoz comment here:
#8474 (comment)
And @gmethvin comment here:
#8474 (comment)
We should list the valid constructors, not those the user has defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a quick test and this is what I got:
class OnlyConfigModule(val config: Config) extends AbstractModule {
override def configure(): Unit = ()
}
val env = Environment.simple()
val conf = Configuration(
"play.modules.enabled" -> Seq(
classOf[OnlyConfigModule].getName
)
)
val located: Seq[Any] = Modules.locate(env, conf)
and it throws..
play.api.PlayException: No valid public constructors for play.api.inject.OnlyConfigModule.
Expected one of: (com.typesafe.config.Config)
As a user, I would think: that's exactly the constructor that I defined, why it saying that it is expecting this constructor and still not using it.
:O You are right |
@fagossa any chance to finalize it? |
This got fixed in #10150 |
Pull Request Checklist
Fixes
Fixes #8474.
Purpose
This improves the error message when a
Module
that matches the constructor parameters specified could not be found.Thanks a lot for your time!