IR: wrap exceptions and add file path in per-file lowerings
Also add file path to the wrapped exception in JVM IR codegen
This commit is contained in:
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.codegen;
|
||||
|
||||
import org.jetbrains.kotlin.util.ExceptionUtilKt;
|
||||
|
||||
import static org.jetbrains.kotlin.utils.ExceptionUtilsKt.rethrow;
|
||||
|
||||
public class CompilationErrorHandler {
|
||||
public static void reportException(Throwable exception, String fileUrl) {
|
||||
// CompilationException is already supposed to have all information about the context
|
||||
if (exception instanceof CompilationException) {
|
||||
try {
|
||||
throw exception;
|
||||
}
|
||||
catch (Throwable t) {
|
||||
throw rethrow(t);
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalStateException(
|
||||
ExceptionUtilKt.getExceptionMessage("Backend", "Exception during code generation", exception, fileUrl),
|
||||
exception
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.codegen
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.progress.ProcessCanceledException
|
||||
import org.jetbrains.kotlin.backend.common.CodegenUtil
|
||||
import org.jetbrains.kotlin.codegen.context.FieldOwnerContext
|
||||
@@ -25,7 +24,6 @@ import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||
import org.jetbrains.kotlin.config.IncrementalCompilation
|
||||
import org.jetbrains.kotlin.config.JvmAnalysisFlags
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticUtils
|
||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||
import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
|
||||
@@ -171,11 +169,7 @@ class MultifileClassCodegenImpl(
|
||||
} catch (e: ProcessCanceledException) {
|
||||
throw e
|
||||
} catch (e: Throwable) {
|
||||
CompilationErrorHandler.reportException(e, file.virtualFile?.url ?: "no file")
|
||||
DiagnosticUtils.throwIfRunningOnServer(e)
|
||||
if (ApplicationManager.getApplication().isInternal) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
CodegenUtil.reportBackendException(e, "multi-file class part code generation", file.virtualFile?.url)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -288,7 +282,7 @@ class MultifileClassCodegenImpl(
|
||||
}
|
||||
|
||||
object DelegateToCompiledMemberGenerationStrategy : FunctionGenerationStrategy() {
|
||||
override fun skipNotNullAssertionsForParameters(): kotlin.Boolean {
|
||||
override fun skipNotNullAssertionsForParameters(): Boolean {
|
||||
throw IllegalStateException("shouldn't be called")
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.codegen;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.SmartList;
|
||||
@@ -28,7 +27,6 @@ import org.jetbrains.kotlin.codegen.context.PackageContext;
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState;
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor;
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticUtils;
|
||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassInfo;
|
||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
@@ -73,12 +71,7 @@ public class PackageCodegenImpl implements PackageCodegen {
|
||||
}
|
||||
catch (Throwable e) {
|
||||
VirtualFile vFile = file.getVirtualFile();
|
||||
CompilationErrorHandler.reportException(e, vFile == null ? "no file" : vFile.getUrl());
|
||||
DiagnosticUtils.throwIfRunningOnServer(e);
|
||||
if (ApplicationManager.getApplication().isInternal()) {
|
||||
//noinspection CallToPrintStackTrace
|
||||
e.printStackTrace();
|
||||
}
|
||||
CodegenUtil.reportBackendException(e, "file facade code generation", vFile == null ? null : vFile.getUrl());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user