Skip to content

Commit

Permalink
Back porting to 1.9.x: MDS doesn't start and shows unfriendly error
Browse files Browse the repository at this point in the history
message after installing - TRUNK-4019
  • Loading branch information
dkayiwa committed Nov 27, 2013
1 parent d26efb8 commit 39034b5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
8 changes: 0 additions & 8 deletions api/src/main/java/org/openmrs/module/Module.java
Expand Up @@ -713,14 +713,6 @@ public void setStartupErrorMessage(String exceptionMessage, Throwable t) {
sb.append(t.getMessage());
sb.append("\n");

// loop over and append all stacktrace elements marking the "openmrs" ones
for (StackTraceElement traceElement : t.getStackTrace()) {
if (traceElement.getClassName().contains("openmrs"))
sb.append(" ** ");
sb.append(traceElement);
sb.append("\n");
}

this.startupErrorMessage = sb.toString();
}

Expand Down
18 changes: 13 additions & 5 deletions api/src/main/java/org/openmrs/module/ModuleFactory.java
Expand Up @@ -284,9 +284,7 @@ public static void startModules() {
// if we failed to start all the modules, error out
if (leftoverModules.size() > 0)
for (Module leftoverModule : leftoverModules) {
String message = "Unable to start module '" + leftoverModule.getName()
+ "'. All required modules are not available: "
+ OpenmrsUtil.join(getMissingRequiredModules(leftoverModule), ", ");
String message = getFailedToStartModuleMessage(leftoverModule);
log.error(message);
leftoverModule.setStartupErrorMessage(message);
notifySuperUsersAboutModuleFailure(leftoverModule);
Expand Down Expand Up @@ -522,8 +520,7 @@ public static Module startModuleInternal(Module module) throws ModuleException {

// check for required modules
if (!requiredModulesStarted(module)) {
throw new ModuleException("Not all required modules are started: "
+ OpenmrsUtil.join(getMissingRequiredModules(module), ", ") + ". ", module.getName());
throw new ModuleException(getFailedToStartModuleMessage(module));
}

// fire up the classloader for this module
Expand Down Expand Up @@ -661,6 +658,17 @@ public static Module startModuleInternal(Module module) throws ModuleException {
return module;
}

/**
* Gets the error message of a module which fails to start.
*
* @param module the module that has failed to start.
* @return the message text.
*/
private static String getFailedToStartModuleMessage(Module module) {
String[] params = {module.getName(), OpenmrsUtil.join(getMissingRequiredModules(module), ", ")};
return Context.getMessageSourceService().getMessage("Module.error.moduleCannotBeStarted", params, Context.getLocale());
}

/**
* Loop over the given module's advice objects and load them into the Context This needs to be
* called for all started modules after every restart of the Spring Application Context
Expand Down
1 change: 1 addition & 0 deletions webapp/src/main/webapp/WEB-INF/messages.properties
Expand Up @@ -1898,6 +1898,7 @@ Module.stopped=Module {0} has been stopped
Module.error=Error processing Module
Module.errorStarting=Error starting Module - {0}
Module.errorClickForDetails=Error starting! Click for details
Module.error.moduleCannotBeStarted=Module {0} cannot be started because it requires the following module(s): {1} Please install and start these modules first.
Module.invalid=Invalid module specified {0}
Module.notStarted=Not Started
Module.loadedAndStarted=Module loaded and started successfully
Expand Down

0 comments on commit 39034b5

Please sign in to comment.