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

Commit

Permalink
Github #106: Avoid using CoreException.getStatus() as stack traces get
Browse files Browse the repository at this point in the history
lost in logging.
  • Loading branch information
marchof committed Sep 11, 2015
1 parent a9bf1c3 commit f015d10
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
*/
public final class EclEmmaStatus {

public final int code;
final int code;

public final int severity;
final int severity;

public final String message;
final String message;

private EclEmmaStatus(int code, int severity, String message) {
this.code = code;
Expand Down Expand Up @@ -68,12 +68,24 @@ public IStatus getStatus(Object param1) {
public static final EclEmmaStatus NO_LOCAL_AGENTJAR_ERROR = new EclEmmaStatus(
5000, IStatus.ERROR, CoreMessages.StatusNO_LOCAL_AGENTJAR_ERROR_message);

/**
* Error while loading a coverage session.
*/
public static final EclEmmaStatus SESSION_LOAD_ERROR = new EclEmmaStatus(
5001, IStatus.ERROR, CoreMessages.StatusSESSION_LOAD_ERROR_message);

/**
* The requested launch type is not known.
*/
public static final EclEmmaStatus UNKOWN_LAUNCH_TYPE_ERROR = new EclEmmaStatus(
5002, IStatus.ERROR, CoreMessages.StatusUNKOWN_LAUNCH_TYPE_ERROR_message);

/**
* Error while merging sessions.
*/
public static final EclEmmaStatus MERGE_SESSIONS_ERROR = new EclEmmaStatus(
5003, IStatus.ERROR, CoreMessages.StatusMERGE_SESSIONS_ERROR_message);

/**
* The execution data file can not be created.
*/
Expand Down Expand Up @@ -104,12 +116,6 @@ public IStatus getStatus(Object param1) {
public static final EclEmmaStatus EXPORT_ERROR = new EclEmmaStatus(5008,
IStatus.ERROR, CoreMessages.StatusEXPORT_ERROR_message);

/**
* Error while importing external coverage session.
*/
public static final EclEmmaStatus IMPORT_ERROR = new EclEmmaStatus(5009,
IStatus.ERROR, CoreMessages.StatusIMPORT_ERROR_message);

/**
* Error while starting the agent server.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ public class CoreMessages extends NLS {
public static String MergingCoverageSessions_task;

public static String StatusNO_LOCAL_AGENTJAR_ERROR_message;
public static String StatusSESSION_LOAD_ERROR_message;
public static String StatusUNKOWN_LAUNCH_TYPE_ERROR_message;
public static String StatusMERGE_SESSIONS_ERROR_message;
public static String StatusEXEC_FILE_CREATE_ERROR_message;
public static String StatusEXEC_FILE_READ_ERROR_message;
public static String StatusAGENT_CONNECT_ERROR_message;
public static String StatusBUNDLE_ANALYSIS_ERROR_message;
public static String StatusEXPORT_ERROR_message;
public static String StatusIMPORT_ERROR_message;
public static String StatusAGENTSERVER_START_ERROR_message;
public static String StatusAGENTSERVER_STOP_ERROR_message;
public static String StatusEXECDATA_DUMP_ERROR_message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.osgi.util.NLS;

import com.mountainminds.eclemma.core.EclEmmaStatus;
import com.mountainminds.eclemma.core.ICoverageSession;
import com.mountainminds.eclemma.core.ISessionListener;
import com.mountainminds.eclemma.core.ISessionManager;
Expand Down Expand Up @@ -80,7 +81,7 @@ protected IStatus run(IProgressMonitor monitor) {
try {
c = new SessionAnalyzer().processSession(session, monitor);
} catch (CoreException e) {
return e.getStatus();
return EclEmmaStatus.SESSION_LOAD_ERROR.getStatus(e);
}
coverage = monitor.isCanceled() ? null : c;
fireCoverageChanged();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ ImportingSession_task=Importing coverage session
MergingCoverageSessions_task=Merging coverage sessions

StatusNO_LOCAL_AGENTJAR_ERROR_message=Local agent jar can not be obtained (code {0}).
StatusSESSION_LOAD_ERROR_message=Error while loading coverage session (code {0}).
StatusUNKOWN_LAUNCH_TYPE_ERROR_message=Unknown launch type {1} (code {0}).
StatusMERGE_SESSIONS_ERROR_message=Error while merging coverage sessions (code {0}).
StatusEXEC_FILE_CREATE_ERROR_message=Execution data file can not be created (code {0}).
StatusEXEC_FILE_READ_ERROR_message=Error while reading execution data file {1} (code {0}).
StatusAGENT_CONNECT_ERROR_message=Error while connecting to JaCoCo agent at address {1} on port {2} (code {0}).
StatusBUNDLE_ANALYSIS_ERROR_message=Error while analyzing package fragment root {1} at {2} (code {0}).
StatusEXPORT_ERROR_message=Error while exporting coverage session (code {0}).
StatusIMPORT_ERROR_message=Error while importing coverage session (code {0}).
StatusAGENTSERVER_START_ERROR_message=Error while starting the agent server (code {0}).
StatusAGENTSERVER_STOP_ERROR_message=Error while stopping the agent server (code {0}).
StatusEXECDATA_DUMP_ERROR_message=Error while dumping coverage data (code {0}).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected IStatus run(IProgressMonitor monitor) {
} catch (IOException e) {
return EclEmmaStatus.EXECDATA_DUMP_ERROR.getStatus(e);
} catch (CoreException e) {
return e.getStatus();
return EclEmmaStatus.EXECDATA_DUMP_ERROR.getStatus(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import java.net.URL;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.resource.ImageDescriptor;
Expand Down Expand Up @@ -148,10 +147,6 @@ public static void log(Throwable t) {
instance.getLog().log(errorStatus(message, t));
}

public static void log(CoreException t) {
instance.getLog().log(t.getStatus());
}

public static ImageDescriptor getImageDescriptor(String key) {
return loadImage(key).getDescriptor(key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.eclipse.ui.handlers.HandlerUtil;

import com.mountainminds.eclemma.core.CoverageTools;
import com.mountainminds.eclemma.core.EclEmmaStatus;
import com.mountainminds.eclemma.core.launching.ICoverageLaunch;
import com.mountainminds.eclemma.internal.ui.ContextHelp;
import com.mountainminds.eclemma.internal.ui.EclEmmaUIPlugin;
Expand Down Expand Up @@ -122,7 +123,7 @@ protected IStatus run(IProgressMonitor monitor) {
.getBoolean(UIPreferences.PREF_RESET_ON_DUMP);
launch.requestDump(reset);
} catch (CoreException e) {
return e.getStatus();
return EclEmmaStatus.DUMP_REQUEST_ERROR.getStatus(e);
}
return Status.OK_STATUS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.ui.handlers.HandlerUtil;

import com.mountainminds.eclemma.core.CoverageTools;
import com.mountainminds.eclemma.core.EclEmmaStatus;
import com.mountainminds.eclemma.core.ICoverageSession;
import com.mountainminds.eclemma.core.ISessionManager;
import com.mountainminds.eclemma.internal.ui.UIMessages;
Expand Down Expand Up @@ -70,7 +71,7 @@ protected IStatus run(IProgressMonitor monitor) {
try {
sm.mergeSessions(sessions, description, monitor);
} catch (CoreException e) {
return e.getStatus();
return EclEmmaStatus.MERGE_SESSIONS_ERROR.getStatus(e);
}
return Status.OK_STATUS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.dialogs.ErrorDialog;
Expand Down Expand Up @@ -95,13 +94,8 @@ public void run(IProgressMonitor monitor)
final String title = UIMessages.ExportReportErrorDialog_title;
String msg = UIMessages.ExportReportErrorDialog_message;
msg = NLS.bind(msg, session.getDescription());
final IStatus status;
if (ex instanceof CoreException) {
status = ((CoreException) ex).getStatus();
} else {
status = EclEmmaUIPlugin.errorStatus(String.valueOf(ex.getMessage()),
ex);
}
final IStatus status = EclEmmaUIPlugin.errorStatus(
String.valueOf(ex.getMessage()), ex);
ErrorDialog.openError(getShell(), title, msg, status);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.dialogs.ErrorDialog;
Expand Down Expand Up @@ -98,13 +97,8 @@ public void run(IProgressMonitor monitor)
EclEmmaUIPlugin.log(ex);
final String title = UIMessages.ImportReportErrorDialog_title;
final String msg = UIMessages.ImportReportErrorDialog_message;
final IStatus status;
if (ex instanceof CoreException) {
status = ((CoreException) ex).getStatus();
} else {
status = EclEmmaUIPlugin.errorStatus(String.valueOf(ex.getMessage()),
ex);
}
final IStatus status = EclEmmaUIPlugin.errorStatus(
String.valueOf(ex.getMessage()), ex);
ErrorDialog.openError(getShell(), title, msg, status);
return false;
}
Expand Down

0 comments on commit f015d10

Please sign in to comment.