Send source code in exceptions as attachments, not text (common cases)

#KT-17678 In Progress
This commit is contained in:
Dmitry Jemerov
2017-12-29 12:42:11 +01:00
parent 817dadc120
commit 25ea53457e
10 changed files with 88 additions and 137 deletions
@@ -1,17 +1,6 @@
/*
* 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.
* Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.codegen;
@@ -19,14 +8,22 @@ package org.jetbrains.kotlin.codegen;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.diagnostics.DiagnosticUtils;
import org.jetbrains.kotlin.util.ExceptionUtilKt;
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments;
public class CompilationException extends RuntimeException {
public class CompilationException extends KotlinExceptionWithAttachments {
private final PsiElement element;
public CompilationException(@NotNull String message, @Nullable Throwable cause, @Nullable PsiElement element) {
super(ExceptionUtilKt.getExceptionMessage("Back-end (JVM)", message, cause, element), cause);
super(ExceptionUtilKt.getExceptionMessage("Back-end (JVM)", message, cause,
element == null ? null : DiagnosticUtils.atLocation(element)),
cause);
this.element = element;
if (element != null) {
withAttachment("element.kt", element.getText());
}
}
@Nullable
@@ -1,21 +1,11 @@
/*
* 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.
* Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.codegen
import com.intellij.openapi.diagnostic.Attachment
import com.intellij.openapi.diagnostic.Logger
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext
@@ -23,7 +13,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext
object ExceptionLogger {
@JvmStatic
fun logDescriptorNotFound(problemDescription: String, psi: PsiElement): AssertionError {
LOG.error(problemDescription, psi.getElementTextWithContext())
LOG.error(problemDescription, Attachment("psi.kt", psi.getElementTextWithContext()))
throw AssertionError(problemDescription)
}
@@ -1,17 +1,6 @@
/*
* 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.
* Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.codegen.binding;
@@ -33,6 +22,7 @@ import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils;
import org.jetbrains.kotlin.util.slicedMap.BasicWritableSlice;
import org.jetbrains.kotlin.util.slicedMap.Slices;
import org.jetbrains.kotlin.util.slicedMap.WritableSlice;
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments;
import org.jetbrains.org.objectweb.asm.Type;
import java.util.*;
@@ -124,7 +114,8 @@ public class CodegenBinding {
return asmTypeForAnonymousClass(bindingContext, variableDescriptor);
}
throw new IllegalStateException("Couldn't compute ASM type for " + PsiUtilsKt.getElementTextWithContext(expression));
throw new KotlinExceptionWithAttachments("Couldn't compute ASM type for expression")
.withAttachment("expression.kt", PsiUtilsKt.getElementTextWithContext(expression));
}
@NotNull