#EA-79158 Report code fragment when translator throws an exception. It should help to get a code sample for this issues and all similar issues.

This commit is contained in:
Alexey Andreev
2016-02-17 12:55:49 +03:00
parent 0283fea835
commit 133402c1ca
3 changed files with 54 additions and 6 deletions
@@ -0,0 +1,28 @@
/*
* Copyright 2010-2016 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.js.facade.exceptions;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.psi.psiUtil.PsiUtilsKt;
public class TranslationRuntimeException extends RuntimeException {
public TranslationRuntimeException(@NotNull PsiElement element, @Nullable Throwable cause) {
super("Unexpected error occurred compiling the following fragment: " + PsiUtilsKt.getTextWithLocation(element), cause);
}
}
@@ -20,6 +20,7 @@ import com.google.dart.compiler.backend.js.ast.*;
import gnu.trove.THashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor;
import org.jetbrains.kotlin.js.facade.exceptions.TranslationRuntimeException;
import org.jetbrains.kotlin.js.translate.context.Namer;
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
import org.jetbrains.kotlin.js.translate.general.AbstractTranslator;
@@ -63,7 +64,18 @@ public final class PackageDeclarationTranslator extends AbstractTranslator {
packageFragmentToTranslator.put(packageFragment, translator);
}
translator.translate(file);
try {
translator.translate(file);
}
catch (TranslationRuntimeException e) {
throw e;
}
catch (RuntimeException e) {
throw new TranslationRuntimeException(file, e);
}
catch (AssertionError e) {
throw new TranslationRuntimeException(file, e);
}
}
for (PackageTranslator translator : packageFragmentToTranslator.values()) {
@@ -24,10 +24,7 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor;
import org.jetbrains.kotlin.idea.MainFunctionDetector;
import org.jetbrains.kotlin.js.config.Config;
import org.jetbrains.kotlin.js.facade.MainCallParameters;
import org.jetbrains.kotlin.js.facade.exceptions.MainFunctionNotFoundException;
import org.jetbrains.kotlin.js.facade.exceptions.TranslationException;
import org.jetbrains.kotlin.js.facade.exceptions.TranslationInternalException;
import org.jetbrains.kotlin.js.facade.exceptions.UnsupportedFeatureException;
import org.jetbrains.kotlin.js.facade.exceptions.*;
import org.jetbrains.kotlin.js.translate.callTranslator.CallTranslator;
import org.jetbrains.kotlin.js.translate.context.Namer;
import org.jetbrains.kotlin.js.translate.context.StaticContext;
@@ -105,7 +102,18 @@ public final class Translation {
@NotNull
private static JsNode doTranslateExpression(KtExpression expression, TranslationContext context) {
return expression.accept(new ExpressionVisitor(), context);
try {
return expression.accept(new ExpressionVisitor(), context);
}
catch (TranslationRuntimeException e) {
throw e;
}
catch (RuntimeException e) {
throw new TranslationRuntimeException(expression, e);
}
catch (AssertionError e) {
throw new TranslationRuntimeException(expression, e);
}
}
@NotNull