Skip to content

Commit

Permalink
Improve error thrown in UIWorkingSetWizardsAuto.deleteResources() ecl…
Browse files Browse the repository at this point in the history
…ipse-platform#275

Find the most severe status in the caught exception and use its stack
trace in order to be able to see where the error originated.
  • Loading branch information
fedejeanne committed Jun 21, 2023
1 parent 99fc65d commit 1d2565a
Showing 1 changed file with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardDialog;
Expand Down Expand Up @@ -99,11 +100,42 @@ private void deleteResources() {

} catch (CoreException e) {
TestPlugin.getDefault().getLog().log(e.getStatus());
throw new AssertionError(e);
throw createAssertionError(e);
}

}

private AssertionError createAssertionError(CoreException originalException) {
Throwable cause = originalException.getCause();
if (cause == null) {
IStatus mostSevere = findMostSevere(originalException.getStatus());
cause = mostSevere.getException();
}

return new AssertionError(originalException.getMessage(), cause);
}

private IStatus findMostSevere(IStatus status) {
if (!status.isMultiStatus()) {
return status;
}

IStatus mostSevere = null;

for (IStatus childStatus : status.getChildren()) {
IStatus mostSevereChild = findMostSevere(childStatus);
if (mostSevere == null || mostSevereChild.getSeverity() > mostSevere.getSeverity()) {
mostSevere = mostSevereChild;
}
}

if (mostSevere == null) {
mostSevere = status;
}

return mostSevere;
}

private Shell getShell() {
return DialogCheck.getShell();
}
Expand Down

0 comments on commit 1d2565a

Please sign in to comment.