Skip to content

Commit

Permalink
Merge pull request #30 from damienbiggs/topic/exception
Browse files Browse the repository at this point in the history
Logging: Log stack trace if exception message is null
  • Loading branch information
jswager committed May 18, 2015
2 parents cf72e1b + c1480f1 commit b140a6b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,16 @@ public VSphereBuildStep getBuildStep() {

@Override
public boolean perform(final AbstractBuild<?, ?> build, final Launcher launcher, final BuildListener listener) {
try {
VSphere vsphere = null;
try {
EnvVars env = build.getEnvironment(listener);
env.overrideAll(build.getBuildVariables()); // Add in matrix axes..
String expandedServerName = env.expand(serverName);

startLogs(listener.getLogger(), expandedServerName);
//Need to ensure this server is same as one that was previously saved.
//TODO - also need to improve logging here.
VSphere vsphere;

// select by hash if we have one
if (serverHash != null) {
vsphere = VSphereBuildStep.VSphereBuildStepDescriptor.getVSphereCloudByHash(serverHash).vSphereInstance();
Expand All @@ -86,15 +87,16 @@ public boolean perform(final AbstractBuild<?, ?> build, final Launcher launcher,
}

buildStep.setVsphere(vsphere);

Boolean buildStepResult = buildStep.perform(build, launcher, listener);
vsphere.disconnect();

return buildStepResult;
return buildStep.perform(build, launcher, listener);
} catch (Exception e) {
VSphereLogger.vsLogger(listener.getLogger(), e.getMessage());
}
return false;
VSphereLogger.vsLogger(listener.getLogger(), e);
} finally {
if (vsphere != null) {
vsphere.disconnect();
}
}
return false;
}

private void startLogs(PrintStream logger, String serverName){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,23 @@ public class VSphereLogger {
* checks the verboseOutput flag and writes to the logger as appropriate.
*
* @param logger - logger that should receive the information
* @param log - string to be sent to the stream
* @param force - forces the output the stream, overwriting the verboseOutput flag.
*/
public static void vsLogger(PrintStream logger, String str){
if(logger!=null){
logger.println("["+Messages.VSphereLogger_title()+"] "+str);
}
}

public static void vsLogger(PrintStream logger, Exception e){
if(logger ==null) {
return;
}

if (e.getMessage() != null) {
logger.println("["+Messages.VSphereLogger_title()+"] Exception: " + e.getMessage());
} else {
logger.println("["+Messages.VSphereLogger_title()+"] Exception message was null, stack trace");
e.printStackTrace(logger);
}
}
}

0 comments on commit b140a6b

Please sign in to comment.