Skip to content

Commit

Permalink
test #975: display dialog when backend dies
Browse files Browse the repository at this point in the history
  • Loading branch information
vladdu committed Dec 14, 2011
1 parent 326bb0e commit d81a5b6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import java.io.OutputStream;
import java.io.PrintWriter;

import org.erlide.core.common.CommonUtils;
import org.erlide.core.MessageReporter;
import org.erlide.core.MessageReporter.ReporterPosition;
import org.erlide.core.common.LogUtil;
import org.erlide.jinterface.ErlLogger;

Expand Down Expand Up @@ -46,15 +47,29 @@ public void run() {
do {
try {
final int v = process.waitFor();
final String msg = "Backend '%s' terminated with exit code %d.";
ErlLogger.error(msg, nodeName, v);
final String msg = String.format(
"Backend '%s' terminated with exit code %d.", nodeName,
v);

String report = null;
// 129 = SIGHUP (probably logout, ignore)
// 143 = SIGTERM (probably logout, ignore)
// 137 = SIGKILL (probably killed by user)
if (v > 1 && v != 143 && v != 129 && v != 137
&& CommonUtils.isEricssonUser()) {
createReport(v, msg);
if (v > 1 && v != 143 && v != 129 && v != 137) {
ErlLogger.error(msg);
report = createReport(v, msg);
final String reportMsg = report != null ? "\n\n"
+ "An error log has been created at "
+ report
+ ".\nPlease report the problem so that we can fix it."
: "";
final String bigMsg = msg
+ "\n\n"
+ "This error is not recoverable, please restart your Eclipse instance."
+ reportMsg;
MessageReporter.showError(bigMsg, ReporterPosition.MODAL);
} else {
ErlLogger.info(msg);
}
// FIXME backend.setExitStatus(v);
return;
Expand All @@ -63,13 +78,14 @@ public void run() {
} while (true);
}

private void createReport(final int v, final String msg) {
private String createReport(final int v, final String msg) {
final String plog = LogUtil.fetchPlatformLog();
final String elog = LogUtil.fetchErlideLog();
final String slog = LogUtil.fetchStraceLog(workingDir + "/" + nodeName
+ ".strace");
final String delim = "\n==================================\n";
final File report = new File(LogUtil.getReportFile());
final String reportFile = LogUtil.getReportFile();
final File report = new File(reportFile);
try {
report.createNewFile();
final OutputStream out = new FileOutputStream(report);
Expand All @@ -93,6 +109,7 @@ private void createReport(final int v, final String msg) {
} catch (final IOException e) {
ErlLogger.warn(e);
}
return reportFile;
}

}
37 changes: 23 additions & 14 deletions org.erlide.ui/src/org/erlide/ui/UIMessageReporter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.erlide.ui;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.progress.UIJob;
import org.erlide.core.MessageReporter;
import org.erlide.ui.util.PopupDialog;

Expand All @@ -11,19 +15,24 @@ public UIMessageReporter() {
@Override
public void displayMessage(final MessageType type, final String message,
final ReporterPosition style) {
switch (style) {
case MODAL:
PopupDialog.showModalDialog("erlide " + type, message);
break;
case CENTER:
PopupDialog.showDialog("erlide " + type, message, 3000);
break;
case CORNER:
PopupDialog.showBalloon("erlide " + type, message, 3000);
break;
default:
break;
}
new UIJob("crashed backend") {
@Override
public IStatus runInUIThread(final IProgressMonitor monitor) {
switch (style) {
case MODAL:
PopupDialog.showModalDialog("erlide " + type, message);
break;
case CENTER:
PopupDialog.showDialog("erlide " + type, message, 3000);
break;
case CORNER:
PopupDialog.showBalloon("erlide " + type, message, 3000);
break;
default:
break;
}
return Status.OK_STATUS;
}
}.schedule();
}

}

0 comments on commit d81a5b6

Please sign in to comment.