Send source code in exceptions as attachments, not text (common cases)
#KT-17678 In Progress
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.resolve.lazy
|
||||
@@ -19,6 +8,7 @@ package org.jetbrains.kotlin.resolve.lazy
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext
|
||||
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
|
||||
|
||||
interface AbsentDescriptorHandler {
|
||||
fun diagnoseDescriptorNotFound(declaration: KtDeclaration): DeclarationDescriptor
|
||||
@@ -29,5 +19,9 @@ class BasicAbsentDescriptorHandler : AbsentDescriptorHandler {
|
||||
}
|
||||
|
||||
class NoDescriptorForDeclarationException @JvmOverloads constructor(declaration: KtDeclaration, additionalDetails: String? = null) :
|
||||
IllegalStateException("Descriptor wasn't found for declaration $declaration\n${declaration.getElementTextWithContext()}"
|
||||
+ (additionalDetails?.let { "\n---------------------------------------------------\n$it" } ?: ""))
|
||||
KotlinExceptionWithAttachments("Descriptor wasn't found for declaration $declaration"
|
||||
+ (additionalDetails?.let { "\n---------------------------------------------------\n$it" } ?: "")) {
|
||||
init {
|
||||
withAttachment("declaration.kt", declaration.getElementTextWithContext())
|
||||
}
|
||||
}
|
||||
|
||||
+5
-15
@@ -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.types.expressions;
|
||||
@@ -41,6 +30,7 @@ import org.jetbrains.kotlin.util.KotlinFrontEndException;
|
||||
import org.jetbrains.kotlin.util.LookupTrackerUtilKt;
|
||||
import org.jetbrains.kotlin.util.PerformanceCounter;
|
||||
import org.jetbrains.kotlin.util.ReenteringLazyValueComputationException;
|
||||
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments;
|
||||
|
||||
import static org.jetbrains.kotlin.diagnostics.Errors.TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM;
|
||||
|
||||
@@ -240,8 +230,8 @@ public abstract class ExpressionTypingVisitorDispatcher extends KtVisitor<Kotlin
|
||||
try {
|
||||
// This trows AssertionError in CLI and reports the error in the IDE
|
||||
LOG.error(
|
||||
"Exception while analyzing expression at " + DiagnosticUtils.atLocation(expression) + ":\n" + expression.getText() + "\n",
|
||||
e
|
||||
new KotlinExceptionWithAttachments("Exception while analyzing expression at " + DiagnosticUtils.atLocation(expression), e)
|
||||
.withAttachment("expression.kt", expression.getText())
|
||||
);
|
||||
}
|
||||
catch (AssertionError errorFromLogger) {
|
||||
|
||||
@@ -1,27 +1,20 @@
|
||||
/*
|
||||
* 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.util
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticUtils
|
||||
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
|
||||
|
||||
class KotlinFrontEndException(message: String, cause: Throwable) : RuntimeException(message, cause) {
|
||||
class KotlinFrontEndException(message: String, cause: Throwable) : KotlinExceptionWithAttachments(message, cause) {
|
||||
constructor(
|
||||
message: String,
|
||||
cause: Throwable,
|
||||
element: PsiElement
|
||||
) : this(getExceptionMessage("Front-end", message, cause, element), cause)
|
||||
) : this(getExceptionMessage("Front-end", message, cause, DiagnosticUtils.atLocation(element)), cause) {
|
||||
withAttachment("element.kt", element.text)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +1,17 @@
|
||||
/*
|
||||
* 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.util
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticUtils
|
||||
|
||||
fun getExceptionMessage(
|
||||
subsystemName: String,
|
||||
message: String,
|
||||
cause: Throwable?,
|
||||
element: PsiElement?
|
||||
location: String?
|
||||
): String = ApplicationManager.getApplication().runReadAction<String> {
|
||||
val result = StringBuilder(subsystemName + " Internal error: ").append(message).append("\n")
|
||||
if (cause != null) {
|
||||
@@ -32,9 +19,8 @@ fun getExceptionMessage(
|
||||
result.append("Cause: ").append(causeMessage ?: cause.toString()).append("\n")
|
||||
}
|
||||
|
||||
if (element != null) {
|
||||
result.append("File being compiled and position: ").append(DiagnosticUtils.atLocation(element)).append("\n")
|
||||
result.append("PsiElement: ").append(element.text).append("\n")
|
||||
if (location != null) {
|
||||
result.append("File being compiled and position: ").append(location).append("\n")
|
||||
}
|
||||
else {
|
||||
result.append("Element is unknown")
|
||||
|
||||
+7
-14
@@ -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.asJava.builder
|
||||
@@ -34,6 +23,7 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.psi.debugText.getDebugText
|
||||
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics
|
||||
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
|
||||
|
||||
interface LightClassDataHolder {
|
||||
val javaFileStub: PsiJavaFileStub
|
||||
@@ -107,7 +97,10 @@ fun PsiJavaFileStub.findDelegate(classOrObject: KtClassOrObject): PsiClass {
|
||||
}
|
||||
|
||||
val stubFileText = DebugUtil.stubTreeToString(this)
|
||||
throw IllegalStateException("Couldn't get delegate for ${classOrObject.getDebugText()}\nin $ktFileText\nstub: \n$stubFileText")
|
||||
throw KotlinExceptionWithAttachments("Couldn't get delegate for class")
|
||||
.withAttachment(classOrObject.name ?: "unnamed class or object", classOrObject.getDebugText())
|
||||
.withAttachment("file.kt", ktFileText)
|
||||
.withAttachment("stub text", stubFileText)
|
||||
}
|
||||
|
||||
fun PsiJavaFileStub.findDelegate(classFqName: FqName): PsiClass {
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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.utils
|
||||
|
||||
import com.intellij.openapi.diagnostic.Attachment
|
||||
import com.intellij.openapi.diagnostic.ExceptionWithAttachments
|
||||
|
||||
open class KotlinExceptionWithAttachments : RuntimeException, ExceptionWithAttachments {
|
||||
private val attachments = mutableListOf<Attachment>()
|
||||
|
||||
constructor(message: String) : super(message)
|
||||
|
||||
constructor(message: String?, cause: Throwable?) : super(message, cause)
|
||||
|
||||
override fun getAttachments(): Array<Attachment> = attachments.toTypedArray()
|
||||
|
||||
fun withAttachment(name: String, content: String?): KotlinExceptionWithAttachments {
|
||||
attachments.add(Attachment(name, content ?: "<null>"))
|
||||
return this
|
||||
}
|
||||
}
|
||||
+9
-16
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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.idea.caches.resolve.lightClasses
|
||||
@@ -34,7 +23,10 @@ import org.jetbrains.kotlin.asJava.elements.KtLightFieldImpl
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightMethod
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightMethodImpl
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.psi.NotNullableUserDataProperty
|
||||
import org.jetbrains.kotlin.psi.debugText.getDebugText
|
||||
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
|
||||
|
||||
typealias ExactLightClassContextProvider = () -> LightClassConstructionContext
|
||||
typealias DummyLightClassContextProvider = (() -> LightClassConstructionContext?)?
|
||||
@@ -151,18 +143,19 @@ sealed class LazyLightClassDataHolder(
|
||||
}
|
||||
|
||||
private sealed class LazyLightClassMemberMatchingError(message: String, containingClass: KtLightClass)
|
||||
: AssertionError(message) {
|
||||
: KotlinExceptionWithAttachments(message) {
|
||||
|
||||
init {
|
||||
containingClass.kotlinOrigin?.hasLightClassMatchingErrors = true
|
||||
withAttachment("class.kt", (containingClass as KtElement).getDebugText())
|
||||
}
|
||||
|
||||
class NoMatch(dummyMember: PsiMember, containingClass: KtLightClass) : LazyLightClassMemberMatchingError(
|
||||
"Couldn't match ${dummyMember.debugName} in $containingClass", containingClass
|
||||
"Couldn't match ${dummyMember.debugName}", containingClass
|
||||
)
|
||||
|
||||
class WrongMatch(realMember: PsiMember, dummyMember: PsiMember, containingClass: KtLightClass) : LazyLightClassMemberMatchingError(
|
||||
"Matched ${dummyMember.debugName} to ${realMember.debugName} in $containingClass", containingClass
|
||||
"Matched ${dummyMember.debugName} to ${realMember.debugName}", containingClass
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user