Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Improve debug for message "Module could not be initialized" #46

Closed
GeeH opened this issue Jun 28, 2016 · 1 comment
Closed

Improve debug for message "Module could not be initialized" #46

GeeH opened this issue Jun 28, 2016 · 1 comment

Comments

@GeeH
Copy link
Contributor

GeeH commented Jun 28, 2016

This issue has been moved from the zendframework repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html


Original Issue: https://api.github.com/repos/zendframework/zendframework/issues/7578
User: @noisebleed
Created On: 2015-06-06T22:29:04Z
Updated At: 2015-10-21T17:23:04Z
Body
If a module fails to load for some reason as a user we get:

Uncaught exception 'Zend\\ModuleManager\\Exception\\RuntimeException' with message
'Module (MyModule) could not be initialized.'

Can this message be improved and show something more relevant? There isn't information to track the source of this issue and we end up in StackOverflow or any other tech medium looking for possible causes without really knowing what's wrong.

If there is something already available in ZF2 that might help please let know.

Note: Found in ZF-2.2.7, may affect master as well, haven't verified.

Thanks.


Comment

User: @Martin-P
Created On: 2015-06-12T21:53:02Z
Updated At: 2015-06-12T21:53:02Z
Body
When you look at the code there is only a check if the variable $module is an object.
See:

if (!is_object($module)) {
throw new Exception\RuntimeException(sprintf(
'Module (%s) could not be initialized.',
$event->getModuleName()
));
}

Can this message be improved and show something more relevant?

Wat would be your suggestion?


Comment

User: @samsonasik
Created On: 2015-07-03T23:52:13Z
Updated At: 2015-07-03T23:52:13Z
Body
I think the exception can be improved by something like:

Module (MyModule) could not be initialized. Make sure you have Module class with MyModule namespace and check the case (uppercase/lowercase) module naming.

Comment

User: @noisebleed
Created On: 2015-07-09T09:56:16Z
Updated At: 2015-07-09T09:56:16Z
Body
@samsonasik, @Martin-P the issue is not the phrasing. I've got that message recently and I needed a lot of time to actually sort out the issue, using Xdebug step-by-step until I found the culprit. I think the issue is the original exception not bubbling up. Maybe an issue with my setup? I would like to see the original error instead of the ModuleManager catching every exception that is thrown in a Factory::createService() run.


Comment

User: @Martin-P
Created On: 2015-07-11T17:09:25Z
Updated At: 2015-07-11T17:09:25Z
Body

I think the issue is the original exception not bubbling up.

What do you mean with "original exception"?

I would like to see the original error instead of the ModuleManager catching every exception that is thrown in a Factory::createService() run.

No idea what this is about.

The descriptions you give are not clear to me. If you can not describe in detail what the problem is, it is impossible to fix it. Perhaps you can create a unittest which shows the exact problem?


Comment

User: @noisebleed
Created On: 2015-07-11T19:37:21Z
Updated At: 2015-07-11T19:37:21Z
Body

What do you mean with "original exception"?

An exception thrown while loading a module (in the Module code), linking directly to the error that ultimately has the consequence of ZF2 not being able to load the module.

No idea what this is about.

See my answer above. The only exception I'm getting in the logs is: ModuleManager.php#L195.

Perhaps you can create a unittest which shows the exact problem?

OK. I'll try.


Comment

User: @mtymek
Created On: 2015-07-11T19:39:52Z
Updated At: 2015-07-11T19:39:52Z
Body
I believe he @noisebleed means "previous exception" - it is not passed when "Module could not be initialized" is thrown.


Comment

User: @Martin-P
Created On: 2015-07-11T21:48:20Z
Updated At: 2015-07-11T21:48:20Z
Body

An exception thrown while loading a module (in the Module code)

Just tested with ZF 2.3.3 (which is also an old ZF2 version) and even if I throw an exception in the __construct() of Module.php I see the original exception. I think you just need to update your ZF2 version to a more recent version than 2.2.7. There are also multiple security issues present in version 2.2.7, see these release notes:


@froschdesign
Copy link
Member

Duplicates #3

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

No branches or pull requests

2 participants