platform: catch/log all project initialization errors

This commit is contained in:
Roman Shevchenko
2014-03-27 19:08:00 +01:00
parent dfa3ef17fb
commit 53d5579afa
2 changed files with 62 additions and 42 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -227,26 +227,33 @@ public class ProgressManagerImpl extends ProgressManager implements Disposable{
@Override
public <T, E extends Exception> T runProcessWithProgressSynchronously(@NotNull final ThrowableComputable<T, E> process,
@NotNull @Nls String progressTitle,
boolean canBeCanceled,
@Nullable Project project) throws E {
@NotNull @Nls String progressTitle,
boolean canBeCanceled,
@Nullable Project project) throws E {
final Ref<T> result = new Ref<T>();
final Ref<E> exceptionRef = new Ref<E>();
Task.Modal task = new Task.Modal(project, progressTitle, canBeCanceled) {
final Ref<Throwable> exception = new Ref<Throwable>();
runProcessWithProgressSynchronously(new Task.Modal(project, progressTitle, canBeCanceled) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
try {
T compute = process.compute();
result.set(compute);
}
catch (Exception e) {
exceptionRef.set((E)e);
catch (Throwable t) {
exception.set(t);
}
}
};
runProcessWithProgressSynchronously(task, null);
if (!exceptionRef.isNull()) throw exceptionRef.get();
}, null);
if (!exception.isNull()) {
Throwable t = exception.get();
if (t instanceof Error) throw (Error)t;
if (t instanceof RuntimeException) throw (RuntimeException)t;
@SuppressWarnings("unchecked") E e = (E)t;
throw e;
}
return result.get();
}
@@ -236,11 +236,11 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt
}
return project;
}
catch (final Exception e) {
LOG.info(e);
Messages.showErrorDialog(message(e), ProjectBundle.message("project.load.default.error"));
catch (Throwable t) {
LOG.info(t);
Messages.showErrorDialog(message(t), ProjectBundle.message("project.load.default.error"));
return null;
}
return null;
}
@NonNls
@@ -260,7 +260,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt
}
private void initProject(@NotNull ProjectImpl project, @Nullable ProjectImpl template) throws IOException {
final ProgressIndicator indicator = myProgressManager.getProgressIndicator();
ProgressIndicator indicator = myProgressManager.getProgressIndicator();
if (indicator != null && !project.isDefault()) {
indicator.setText(ProjectBundle.message("loading.components.for", project.getName()));
indicator.setIndeterminate(true);
@@ -268,6 +268,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt
ApplicationManager.getApplication().getMessageBus().syncPublisher(ProjectLifecycleListener.TOPIC).beforeProjectLoaded(project);
boolean succeed = false;
try {
if (template != null) {
project.getStateStore().loadProjectFromTemplate(template);
@@ -277,14 +278,12 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt
}
project.loadProjectComponents();
project.init();
succeed = true;
}
catch (IOException e) {
scheduleDispose(project);
throw e;
}
catch (ProcessCanceledException e) {
scheduleDispose(project);
throw e;
finally {
if (!succeed) {
scheduleDispose(project);
}
}
}
@@ -324,8 +323,9 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt
initProject(project, null);
return project;
}
catch (StateStorageException e) {
throw new IOException(e.getMessage());
catch (Throwable t) {
LOG.info(t);
throw new IOException(t);
}
}
@@ -351,22 +351,23 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt
public synchronized Project getDefaultProject() {
LOG.assertTrue(!myDefaultProjectWasDisposed, "Default project has been already disposed!");
if (myDefaultProject == null) {
try {
myDefaultProject = createProject(null, "", true, ApplicationManager.getApplication().isUnitTestMode());
initProject(myDefaultProject, null);
myDefaultProjectRootElement = null;
}
catch (IOException e) {
LOG.error(e);
}
catch (StateStorageException e) {
LOG.error(e);
}
ProgressManager.getInstance().executeNonCancelableSection(new Runnable() {
@Override
public void run() {
try {
myDefaultProject = createProject(null, "", true, ApplicationManager.getApplication().isUnitTestMode());
initProject(myDefaultProject, null);
myDefaultProjectRootElement = null;
}
catch (Throwable t) {
LOG.error(t);
}
}
});
}
return myDefaultProject;
}
public Element getDefaultProjectRootElement() {
return myDefaultProjectRootElement;
}
@@ -404,8 +405,8 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt
if (isLight(project)) {
throw new AssertionError("must not open light project");
}
final Application application = ApplicationManager.getApplication();
final Application application = ApplicationManager.getApplication();
if (!application.isUnitTestMode() && !((ProjectEx)project).getStateStore().checkVersion()) {
return false;
}
@@ -417,10 +418,11 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt
myOpenProjects.add(project);
cacheOpenProjects();
}
fireProjectOpened(project);
waitForFileWatcher(project);
final StartupManagerImpl startupManager = (StartupManagerImpl)StartupManager.getInstance(project);
waitForFileWatcher(project);
boolean ok = myProgressManager.runProcessWithProgressSynchronously(new Runnable() {
@Override
public void run() {
@@ -536,8 +538,19 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt
return null;
}
final Project project = loadProjectWithProgress(filePath);
if (project == null) return null;
final Project project;
try {
project = loadProjectWithProgress(filePath);
if (project == null) return null;
}
catch (IOException e) {
LOG.info(e);
throw e;
}
catch (Throwable t) {
LOG.info(t);
throw new IOException(t);
}
if (!conversionResult.conversionNotNeeded()) {
StartupManager.getInstance(project).registerPostStartupActivity(new Runnable() {