1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-15 04:55:22 +02:00

Bug 552481: Expose error when wizard fails

An example of a failure that used to be buried in the log is a project
that failed to be created due to different case resource exception.

Change-Id: I513f0dbd36bbb116a5c7de296f7459d200d65af5
This commit is contained in:
Jonah Graham 2019-11-13 12:58:43 -05:00
parent 59b8262ea5
commit d8e577d154
2 changed files with 60 additions and 2 deletions

View file

@ -99,8 +99,10 @@ public abstract class TemplateWizard extends BasicNewResourceWizard {
return ResourcesPlugin.getWorkspace().getRoot(); return ResourcesPlugin.getWorkspace().getRoot();
} }
}); });
} catch (InterruptedException | InvocationTargetException e) { } catch (InterruptedException e) {
throw new RuntimeException(e); Activator.errorDialog(getShell(), "Error Creating Project", "Project cannot be created", e, true);
} catch (InvocationTargetException e) {
Activator.errorDialog(getShell(), "Error Creating Project", "Project cannot be created", e.getTargetException(), true);
} }
return true; return true;
} }

View file

@ -10,6 +10,8 @@ package org.eclipse.tools.templates.ui.internal;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.plugin.AbstractUIPlugin; import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
@ -17,6 +19,7 @@ import org.osgi.framework.BundleContext;
* The activator class controls the plug-in life cycle * The activator class controls the plug-in life cycle
*/ */
public class Activator extends AbstractUIPlugin { public class Activator extends AbstractUIPlugin {
public static final String PLUGIN_ID = "org.eclipse.tools.templates.ui"; //$NON-NLS-1$
private static Activator plugin; private static Activator plugin;
@ -52,4 +55,57 @@ public class Activator extends AbstractUIPlugin {
} }
} }
/**
* Creates an error status.
*
* @noreference This method is not intended to be referenced by clients.
*/
public static Status createErrorStatus(String message) {
return createErrorStatus(message, null);
}
/**
* Creates an error status.
*
* @noreference This method is not intended to be referenced by clients.
*/
public static Status createErrorStatus(String message, Throwable e) {
return new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, message, e);
}
/**
* @noreference This method is not intended to be referenced by clients.
*/
public static void log(IStatus status) {
plugin.getLog().log(status);
}
/**
* @noreference This method is not intended to be referenced by clients.
*/
public static void log(String message, Throwable e) {
log(createErrorStatus(message, e));
}
/**
* Utility method with conventions
*/
public static void errorDialog(Shell shell, String title, String message, Throwable t, boolean logError) {
if (logError)
log(message, t);
IStatus status;
if (t instanceof CoreException) {
status = ((CoreException) t).getStatus();
// if the 'message' resource string and the IStatus' message are the same,
// don't show both in the dialog
if (status != null && message.equals(status.getMessage())) {
message = null;
}
} else {
status = new Status(IStatus.ERROR, PLUGIN_ID, -1, "Internal Error: ", t); //$NON-NLS-1$
}
ErrorDialog.openError(shell, title, message, status);
}
} }