Do not wrap and display cause's message in compiler exceptions
In case the wrapped exception message contains some long text (bytecode, IR, etc.), it could be displayed several times in the same stack trace, which significantly worsened the experience of parsing such stack traces
This commit is contained in:
@@ -18,8 +18,19 @@ package org.jetbrains.kotlin.codegen;
|
||||
|
||||
import org.jetbrains.kotlin.util.ExceptionUtilKt;
|
||||
|
||||
import static org.jetbrains.kotlin.utils.ExceptionUtilsKt.rethrow;
|
||||
|
||||
public interface CompilationErrorHandler {
|
||||
CompilationErrorHandler THROW_EXCEPTION = (exception, 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
|
||||
|
||||
@@ -317,9 +317,8 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
catch (ProcessCanceledException | CompilationException e) {
|
||||
throw e;
|
||||
}
|
||||
catch (Throwable error) {
|
||||
String message = error.getMessage();
|
||||
throw new CompilationException(message != null ? message : "null", error, selector);
|
||||
catch (Throwable e) {
|
||||
throw new CompilationException("Failed to generate expression: " + selector.getClass().getSimpleName(), e, selector);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -985,16 +985,14 @@ public class FunctionCodegen {
|
||||
catch (ProcessCanceledException e) {
|
||||
throw e;
|
||||
}
|
||||
catch (Throwable t) {
|
||||
catch (Throwable e) {
|
||||
String bytecode = renderByteCodeIfAvailable(mv);
|
||||
throw new CompilationException(
|
||||
"wrong code generated\n" +
|
||||
(description != null ? " for " + description : "") +
|
||||
t.getClass().getName() +
|
||||
" " +
|
||||
t.getMessage() +
|
||||
(bytecode != null ? "\nbytecode:\n" + bytecode : ""),
|
||||
t, method);
|
||||
"wrong bytecode generated" +
|
||||
(description != null ? " for " + description : "") + "\n" +
|
||||
(bytecode != null ? bytecode : "<no bytecode>"),
|
||||
e, method
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user