mirror of
https://github.com/apple/pkl.git
synced 2026-04-25 09:48:41 +02:00
Revert error coloring (for development on dedicated branch) (#565)
This commit is contained in:
committed by
GitHub
parent
527d236ba4
commit
5cc2ea2d00
@@ -8,7 +8,6 @@ net.sf.jopt-simple:jopt-simple:5.0.4=jmh,jmhCompileClasspath,jmhImplementationDe
|
||||
org.apache.commons:commons-math3:3.6.1=jmh,jmhCompileClasspath,jmhImplementationDependenciesMetadata,jmhRuntimeClasspath
|
||||
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeOnlyDependenciesMetadata
|
||||
org.assertj:assertj-core:3.26.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.fusesource.jansi:jansi:2.4.1=jmh,jmhRuntimeClasspath
|
||||
org.graalvm.compiler:compiler:23.0.2=graal
|
||||
org.graalvm.sdk:graal-sdk:23.0.2=graal,jmh,jmhRuntimeClasspath,truffle
|
||||
org.graalvm.truffle:truffle-api:23.0.2=graal,jmh,jmhRuntimeClasspath,truffle
|
||||
|
||||
@@ -37,9 +37,6 @@ tasks.withType<Test>().configureEach {
|
||||
// enable checking of stdlib return types
|
||||
systemProperty("org.pkl.testMode", "true")
|
||||
|
||||
// Disable colour output in tests
|
||||
systemProperty("org.fusesource.jansi.Ansi.disable", "true")
|
||||
|
||||
reports.named("html") { enabled = true }
|
||||
|
||||
testLogging { exceptionFormat = TestExceptionFormat.FULL }
|
||||
|
||||
@@ -7,7 +7,6 @@ net.bytebuddy:byte-buddy:1.14.16=testCompileClasspath,testImplementationDependen
|
||||
net.java.dev.jna:jna:5.6.0=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeOnlyDependenciesMetadata
|
||||
org.assertj:assertj-core:3.26.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.fusesource.jansi:jansi:2.4.1=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.graalvm.sdk:graal-sdk:23.0.2=testRuntimeClasspath
|
||||
org.graalvm.truffle:truffle-api:23.0.2=testRuntimeClasspath
|
||||
org.jetbrains.intellij.deps:trove4j:1.0.20200330=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
|
||||
@@ -101,4 +101,4 @@ org.xmlunit:xmlunit-core:2.10.0=testCompileClasspath,testImplementationDependenc
|
||||
org.xmlunit:xmlunit-legacy:2.10.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.xmlunit:xmlunit-placeholders:2.10.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.yaml:snakeyaml:2.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
empty=annotationProcessor,archives,compile,intransitiveDependenciesMetadata,javaExecutable,kotlinCompilerPluginClasspath,kotlinNativeCompilerPluginClasspath,kotlinScriptDef,kotlinScriptDefExtensions,runtime,runtimeOnlyDependenciesMetadata,shadow,signatures,sourcesJar,stagedAlpineLinuxAmd64Executable,stagedLinuxAarch64Executable,stagedLinuxAmd64Executable,stagedMacAarch64Executable,stagedMacAmd64Executable,stagedWindowsAmd64Executable,testAnnotationProcessor,testApiDependenciesMetadata,testCompile,testCompileOnly,testCompileOnlyDependenciesMetadata,testIntransitiveDependenciesMetadata,testKotlinScriptDef,testKotlinScriptDefExtensions,testRuntime
|
||||
empty=annotationProcessor,archives,compile,intransitiveDependenciesMetadata,javaExecutable,kotlinCompilerPluginClasspath,kotlinNativeCompilerPluginClasspath,kotlinScriptDef,kotlinScriptDefExtensions,runtime,runtimeOnlyDependenciesMetadata,shadow,signatures,sourcesJar,stagedAlpineLinuxAmd64Executable,stagedLinuxAarch64Executable,stagedLinuxAmd64Executable,stagedMacAarch64Executable,stagedMacAmd64Executable,testAnnotationProcessor,testApiDependenciesMetadata,testCompile,testCompileOnly,testCompileOnlyDependenciesMetadata,testIntransitiveDependenciesMetadata,testKotlinScriptDef,testKotlinScriptDefExtensions,testRuntime
|
||||
|
||||
@@ -188,11 +188,7 @@ fun Exec.configureExecutable(
|
||||
// that the "initialize everything at build time" *CLI* option is likely here to stay
|
||||
add("--initialize-at-build-time=")
|
||||
// needed for messagepack-java (see https://github.com/msgpack/msgpack-java/issues/600)
|
||||
// needed for jansi (see
|
||||
// https://github.com/fusesource/jansi/issues/199#issuecomment-1252268229)
|
||||
add(
|
||||
"--initialize-at-run-time=org.msgpack.core.buffer.DirectBufferAccess,org.fusesource.jansi.internal"
|
||||
)
|
||||
add("--initialize-at-run-time=org.msgpack.core.buffer.DirectBufferAccess")
|
||||
add("--no-fallback")
|
||||
add("-H:IncludeResources=org/pkl/core/stdlib/.*\\.pkl")
|
||||
add("-H:IncludeResources=org/jline/utils/.*")
|
||||
|
||||
@@ -89,7 +89,6 @@ constructor(
|
||||
} catch (ex: Exception) {
|
||||
errWriter.appendLine("Error evaluating module ${moduleUri.path}:")
|
||||
errWriter.write(ex.message ?: "")
|
||||
errWriter.write(ex.stackTraceToString())
|
||||
if (moduleUri != sources.last()) {
|
||||
errWriter.appendLine()
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ net.bytebuddy:byte-buddy:1.14.16=testCompileClasspath,testImplementationDependen
|
||||
net.java.dev.jna:jna:5.6.0=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeOnlyDependenciesMetadata
|
||||
org.assertj:assertj-core:3.26.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.fusesource.jansi:jansi:2.4.1=runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.graalvm.sdk:graal-sdk:23.0.2=default,runtimeClasspath,testRuntimeClasspath
|
||||
org.graalvm.truffle:truffle-api:23.0.2=default,runtimeClasspath,testRuntimeClasspath
|
||||
org.jetbrains.intellij.deps:trove4j:1.0.20200330=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
|
||||
@@ -10,7 +10,6 @@ net.bytebuddy:byte-buddy:1.14.16=testCompileClasspath,testImplementationDependen
|
||||
net.java.dev.jna:jna:5.6.0=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath,testRuntimeClasspath
|
||||
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeOnlyDependenciesMetadata
|
||||
org.assertj:assertj-core:3.26.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.fusesource.jansi:jansi:2.4.1=runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.graalvm.sdk:graal-sdk:23.0.2=default,runtimeClasspath,testRuntimeClasspath
|
||||
org.graalvm.truffle:truffle-api:23.0.2=default,runtimeClasspath,testRuntimeClasspath
|
||||
org.jetbrains.intellij.deps:trove4j:1.0.20200330=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
|
||||
|
||||
@@ -8,7 +8,6 @@ net.bytebuddy:byte-buddy:1.14.16=testCompileClasspath,testImplementationDependen
|
||||
net.java.dev.jna:jna:5.6.0=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeOnlyDependenciesMetadata
|
||||
org.assertj:assertj-core:3.26.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.fusesource.jansi:jansi:2.4.1=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.graalvm.sdk:graal-sdk:23.0.2=default,runtimeClasspath,testRuntimeClasspath
|
||||
org.graalvm.truffle:truffle-api:23.0.2=default,runtimeClasspath,testRuntimeClasspath
|
||||
org.jetbrains.intellij.deps:trove4j:1.0.20200330=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
|
||||
@@ -26,7 +26,7 @@ dependencies {
|
||||
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk8")
|
||||
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-common")
|
||||
}
|
||||
implementation(libs.jansi)
|
||||
|
||||
implementation(projects.pklCommons)
|
||||
testImplementation(projects.pklCommonsTest)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ package org.pkl.commons.cli
|
||||
|
||||
import java.io.PrintStream
|
||||
import kotlin.system.exitProcess
|
||||
import org.fusesource.jansi.AnsiConsole
|
||||
|
||||
/** Building block for CLIs. Intended to be called from a `main` method. */
|
||||
fun cliMain(block: () -> Unit) {
|
||||
@@ -28,9 +27,6 @@ fun cliMain(block: () -> Unit) {
|
||||
if (!message.endsWith('\n')) stream.println()
|
||||
}
|
||||
|
||||
// Setup AnsiConsole. This will automatically strip escape codes if
|
||||
// the target shell doesn't appear to support them.
|
||||
AnsiConsole.systemInstall()
|
||||
// Force `native-image` to use system proxies (which does not happen with `-D`).
|
||||
System.setProperty("java.net.useSystemProxies", "true")
|
||||
try {
|
||||
|
||||
@@ -7,7 +7,6 @@ net.java.dev.jna:jna:5.6.0=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
org.apiguardian:apiguardian-api:1.1.2=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeOnlyDependenciesMetadata
|
||||
org.assertj:assertj-core:3.24.2=default
|
||||
org.assertj:assertj-core:3.26.0=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.fusesource.jansi:jansi:2.4.1=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.jetbrains.intellij.deps:trove4j:1.0.20200330=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
org.jetbrains.kotlin:kotlin-compiler-embeddable:1.7.10=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
org.jetbrains.kotlin:kotlin-daemon-embeddable:1.7.10=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
|
||||
@@ -26,7 +26,6 @@ dependencies {
|
||||
api(libs.junitApi)
|
||||
api(libs.junitEngine)
|
||||
api(libs.junitParams)
|
||||
api(libs.jansi)
|
||||
api(projects.pklCommons) // for convenience
|
||||
implementation(libs.assertj)
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ net.bytebuddy:byte-buddy:1.14.16=testCompileClasspath,testImplementationDependen
|
||||
net.java.dev.jna:jna:5.6.0=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeOnlyDependenciesMetadata
|
||||
org.assertj:assertj-core:3.26.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.fusesource.jansi:jansi:2.4.1=pklCodegenJava,runtimeClasspath,testRuntimeClasspath
|
||||
org.graalvm.sdk:graal-sdk:23.0.2=default,pklCodegenJava,runtimeClasspath,testRuntimeClasspath
|
||||
org.graalvm.truffle:truffle-api:23.0.2=default,pklCodegenJava,runtimeClasspath,testRuntimeClasspath
|
||||
org.jetbrains.intellij.deps:trove4j:1.0.20200330=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
|
||||
@@ -11,7 +11,6 @@ net.bytebuddy:byte-buddy:1.14.16=testCompileClasspath,testImplementationDependen
|
||||
net.java.dev.jna:jna:5.6.0=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeOnlyDependenciesMetadata
|
||||
org.assertj:assertj-core:3.26.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.fusesource.jansi:jansi:2.4.1=pklCodegenKotlin,pklConfigJava,runtimeClasspath,testRuntimeClasspath
|
||||
org.graalvm.sdk:graal-sdk:23.0.2=default,pklCodegenKotlin,pklConfigJava,runtimeClasspath,testRuntimeClasspath
|
||||
org.graalvm.truffle:truffle-api:23.0.2=default,pklCodegenKotlin,pklConfigJava,runtimeClasspath,testRuntimeClasspath
|
||||
org.jetbrains.intellij.deps:trove4j:1.0.20200330=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
|
||||
@@ -13,7 +13,6 @@ org.antlr:ST4:4.3=antlr
|
||||
org.antlr:antlr-runtime:3.5.2=antlr
|
||||
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeOnlyDependenciesMetadata
|
||||
org.assertj:assertj-core:3.26.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.fusesource.jansi:jansi:2.4.1=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.graalvm.sdk:graal-sdk:23.0.2=compileClasspath,default,generatorCompileClasspath,generatorImplementationDependenciesMetadata,generatorRuntimeClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.graalvm.truffle:truffle-api:23.0.2=compileClasspath,default,generatorCompileClasspath,generatorImplementationDependenciesMetadata,generatorRuntimeClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.graalvm.truffle:truffle-dsl-processor:23.0.2=annotationProcessor
|
||||
|
||||
@@ -64,8 +64,6 @@ dependencies {
|
||||
|
||||
implementation(libs.snakeYaml)
|
||||
|
||||
implementation(libs.jansi)
|
||||
|
||||
testImplementation(projects.pklCommonsTest)
|
||||
|
||||
add("generatorImplementation", libs.javaPoet)
|
||||
|
||||
@@ -15,23 +15,15 @@
|
||||
*/
|
||||
package org.pkl.core.runtime;
|
||||
|
||||
import static org.fusesource.jansi.Ansi.ansi;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import org.fusesource.jansi.Ansi;
|
||||
import org.fusesource.jansi.Ansi.Color;
|
||||
import org.pkl.core.StackFrame;
|
||||
import org.pkl.core.util.Nullable;
|
||||
|
||||
public final class StackTraceRenderer {
|
||||
private final Function<StackFrame, StackFrame> frameTransformer;
|
||||
|
||||
private static final Ansi.Color frameColor = Color.YELLOW;
|
||||
private static final Ansi.Color lineNumColor = Color.BLUE;
|
||||
private static final Ansi.Color repetitionColor = Color.MAGENTA;
|
||||
|
||||
public StackTraceRenderer(Function<StackFrame, StackFrame> frameTransformer) {
|
||||
this.frameTransformer = frameTransformer;
|
||||
}
|
||||
@@ -48,7 +40,6 @@ public final class StackTraceRenderer {
|
||||
StringBuilder builder,
|
||||
String leftMargin,
|
||||
boolean isFirstElement) {
|
||||
var out = ansi(builder);
|
||||
for (var frame : frames) {
|
||||
if (frame instanceof StackFrameLoop loop) {
|
||||
// ensure a cycle of length 1 doesn't get rendered as a loop
|
||||
@@ -56,28 +47,20 @@ public final class StackTraceRenderer {
|
||||
doRender(loop.frames, null, builder, leftMargin, isFirstElement);
|
||||
} else {
|
||||
if (!isFirstElement) {
|
||||
out.fgBright(frameColor).a(leftMargin).reset().a("\n");
|
||||
builder.append(leftMargin).append("\n");
|
||||
}
|
||||
out.fgBright(frameColor)
|
||||
.a(leftMargin)
|
||||
.a("┌─ ")
|
||||
.reset()
|
||||
.bold()
|
||||
.fg(repetitionColor)
|
||||
.a(Integer.toString(loop.count))
|
||||
.reset()
|
||||
.a(" repetitions of:\n");
|
||||
builder.append(leftMargin).append("┌─ ").append(loop.count).append(" repetitions of:\n");
|
||||
var newLeftMargin = leftMargin + "│ ";
|
||||
doRender(loop.frames, null, builder, newLeftMargin, isFirstElement);
|
||||
if (isFirstElement) {
|
||||
renderHint(hint, builder, newLeftMargin);
|
||||
isFirstElement = false;
|
||||
}
|
||||
out.fgBright(frameColor).a(leftMargin).a("└─").reset().a("\n");
|
||||
builder.append(leftMargin).append("└─\n");
|
||||
}
|
||||
} else {
|
||||
if (!isFirstElement) {
|
||||
out.fgBright(frameColor).a(leftMargin).reset().a('\n');
|
||||
builder.append(leftMargin).append('\n');
|
||||
}
|
||||
renderFrame((StackFrame) frame, builder, leftMargin);
|
||||
}
|
||||
@@ -97,16 +80,14 @@ public final class StackTraceRenderer {
|
||||
|
||||
private void renderHint(@Nullable String hint, StringBuilder builder, String leftMargin) {
|
||||
if (hint == null || hint.isEmpty()) return;
|
||||
var out = ansi(builder);
|
||||
|
||||
out.a('\n');
|
||||
out.fgBright(frameColor).a(leftMargin);
|
||||
out.fgBright(frameColor).bold().a(hint).reset();
|
||||
out.a('\n');
|
||||
builder.append('\n');
|
||||
builder.append(leftMargin);
|
||||
builder.append(hint);
|
||||
builder.append('\n');
|
||||
}
|
||||
|
||||
private void renderSourceLine(StackFrame frame, StringBuilder builder, String leftMargin) {
|
||||
var out = ansi(builder);
|
||||
var originalSourceLine = frame.getSourceLines().get(0);
|
||||
var leadingWhitespace = VmUtils.countLeadingWhitespace(originalSourceLine);
|
||||
var sourceLine = originalSourceLine.strip();
|
||||
@@ -117,36 +98,27 @@ public final class StackTraceRenderer {
|
||||
: sourceLine.length();
|
||||
|
||||
var prefix = frame.getStartLine() + " | ";
|
||||
out.fgBright(frameColor)
|
||||
.a(leftMargin)
|
||||
.fgBright(lineNumColor)
|
||||
.a(prefix)
|
||||
.reset()
|
||||
.a(sourceLine)
|
||||
.a('\n');
|
||||
out.fgBright(frameColor).a(leftMargin).reset();
|
||||
builder.append(leftMargin).append(prefix).append(sourceLine).append('\n');
|
||||
builder.append(leftMargin);
|
||||
//noinspection StringRepeatCanBeUsed
|
||||
for (int i = 1; i < prefix.length() + startColumn; i++) {
|
||||
out.append(' ');
|
||||
builder.append(' ');
|
||||
}
|
||||
|
||||
out.fgRed();
|
||||
//noinspection StringRepeatCanBeUsed
|
||||
for (int i = startColumn; i <= endColumn; i++) {
|
||||
out.a('^');
|
||||
builder.append('^');
|
||||
}
|
||||
out.reset().a('\n');
|
||||
builder.append('\n');
|
||||
}
|
||||
|
||||
private void renderSourceLocation(StackFrame frame, StringBuilder builder, String leftMargin) {
|
||||
var out = ansi(builder);
|
||||
out.fgBright(frameColor).a(leftMargin).reset().a("at ");
|
||||
builder.append(leftMargin).append("at ");
|
||||
if (frame.getMemberName() != null) {
|
||||
out.a(frame.getMemberName());
|
||||
builder.append(frame.getMemberName());
|
||||
} else {
|
||||
out.a("<unknown>");
|
||||
builder.append("<unknown>");
|
||||
}
|
||||
out.a(" (").a(frame.getModuleUri()).a(')').a('\n');
|
||||
builder.append(" (").append(frame.getModuleUri()).append(')').append('\n');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,14 +15,10 @@
|
||||
*/
|
||||
package org.pkl.core.runtime;
|
||||
|
||||
import static org.fusesource.jansi.Ansi.ansi;
|
||||
|
||||
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import org.fusesource.jansi.Ansi;
|
||||
import org.fusesource.jansi.Ansi.Color;
|
||||
import org.pkl.core.Release;
|
||||
import org.pkl.core.util.ErrorMessages;
|
||||
import org.pkl.core.util.Nullable;
|
||||
@@ -31,8 +27,6 @@ import org.pkl.core.util.StringBuilderWriter;
|
||||
public final class VmExceptionRenderer {
|
||||
private final @Nullable StackTraceRenderer stackTraceRenderer;
|
||||
|
||||
private static final Ansi.Color errorColor = Color.RED;
|
||||
|
||||
/**
|
||||
* Constructs an error renderer with the given stack trace renderer. If stack trace renderer is
|
||||
* {@code null}, stack traces will not be included in error output.
|
||||
@@ -79,8 +73,7 @@ public final class VmExceptionRenderer {
|
||||
}
|
||||
|
||||
private void renderException(VmException exception, StringBuilder builder) {
|
||||
var out = ansi(builder);
|
||||
out.fg(errorColor).a("–– Pkl Error ––").reset();
|
||||
var header = "–– Pkl Error ––";
|
||||
|
||||
String message;
|
||||
var hint = exception.getHint();
|
||||
@@ -101,7 +94,7 @@ public final class VmExceptionRenderer {
|
||||
message = exception.getMessage();
|
||||
}
|
||||
|
||||
out.a('\n').fgBright(errorColor).a(message).reset().a('\n');
|
||||
builder.append(header).append('\n').append(message).append('\n');
|
||||
|
||||
// include cause's message unless it's the same as this exception's message
|
||||
if (exception.getCause() != null) {
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
/**
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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.pkl.core
|
||||
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.fusesource.jansi.Ansi
|
||||
import org.junit.jupiter.api.*
|
||||
|
||||
class ErrorColoringTest {
|
||||
companion object {
|
||||
val evaluator by lazy { Evaluator.preconfigured() }
|
||||
|
||||
@AfterAll
|
||||
@JvmStatic
|
||||
fun afterAll() {
|
||||
evaluator.close()
|
||||
}
|
||||
}
|
||||
|
||||
private fun evaluate(program: String, expression: String): Any {
|
||||
return evaluator.evaluateExpression(ModuleSource.text(program), expression)
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
fun setup() {
|
||||
// Enable colouring before each test
|
||||
Ansi.setEnabled(true)
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
fun teardown() {
|
||||
// Disable colouring after each test
|
||||
Ansi.setEnabled(false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `simple error`() {
|
||||
val error = assertThrows<PklException> { evaluate("bar = 2", "bar = 15") }
|
||||
|
||||
assertThat(error)
|
||||
.message()
|
||||
.contains("\u001B[31m–– Pkl Error ––\u001B[m")
|
||||
.contains("\u001B[94m1 | \u001B[m")
|
||||
.contains("\u001B[0;31m^")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `repeated error`() {
|
||||
val error =
|
||||
assertThrows<PklException> {
|
||||
evaluate(
|
||||
"""self: String = "Strings; if they were lazy, you could tie the knot on \(self.take(7))"""",
|
||||
"self"
|
||||
)
|
||||
}
|
||||
assertThat(error)
|
||||
.message()
|
||||
.contains("[91mA stack overflow occurred.[m")
|
||||
.contains("[93m┌─ [0;1;35m")
|
||||
.contains("[m repetitions of:")
|
||||
.contains("[93m│ [94m1 | [m")
|
||||
.contains("[0;31m^^^^[m")
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,6 @@ org.commonmark:commonmark:0.21.0=default
|
||||
org.commonmark:commonmark:0.22.0=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.eclipse.jetty:jetty-util-ajax:9.4.18.v20190429=validator
|
||||
org.eclipse.jetty:jetty-util:9.4.18.v20190429=validator
|
||||
org.fusesource.jansi:jansi:2.4.1=testCompileClasspath,testRuntimeClasspath
|
||||
org.graalvm.js:js:23.0.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.graalvm.regex:regex:23.0.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.graalvm.sdk:graal-sdk:23.0.2=default,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
|
||||
@@ -6,7 +6,6 @@ net.bytebuddy:byte-buddy:1.14.16=testCompileClasspath,testImplementationDependen
|
||||
net.java.dev.jna:jna:5.6.0=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeOnlyDependenciesMetadata
|
||||
org.assertj:assertj-core:3.26.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.fusesource.jansi:jansi:2.4.1=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.graalvm.sdk:graal-sdk:23.0.2=testRuntimeClasspath
|
||||
org.graalvm.truffle:truffle-api:23.0.2=testRuntimeClasspath
|
||||
org.jetbrains.intellij.deps:trove4j:1.0.20200330=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
|
||||
@@ -7,7 +7,6 @@ net.bytebuddy:byte-buddy:1.14.16=testCompileClasspath,testImplementationDependen
|
||||
net.java.dev.jna:jna:5.6.0=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeOnlyDependenciesMetadata
|
||||
org.assertj:assertj-core:3.26.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.fusesource.jansi:jansi:2.4.1=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.jetbrains.intellij.deps:trove4j:1.0.20200330=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
org.jetbrains.kotlin:kotlin-compiler-embeddable:1.7.10=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
org.jetbrains.kotlin:kotlin-daemon-embeddable:1.7.10=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
|
||||
@@ -87,12 +87,6 @@ gradlePluginTests {
|
||||
skippedGradleVersions = listOf()
|
||||
}
|
||||
|
||||
tasks.withType<Test>().configureEach {
|
||||
// Disable colour output in tests
|
||||
// Need additional disablement here because of how Jansi is packaged in the plugin
|
||||
systemProperty("org.pkl.thirdparty.jansiAnsi.disable", "true")
|
||||
}
|
||||
|
||||
signing {
|
||||
publishing.publications.withType(MavenPublication::class.java).configureEach {
|
||||
if (name != "library") {
|
||||
|
||||
@@ -6,7 +6,6 @@ net.bytebuddy:byte-buddy:1.14.16=testCompileClasspath,testImplementationDependen
|
||||
net.java.dev.jna:jna:5.6.0=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeOnlyDependenciesMetadata
|
||||
org.assertj:assertj-core:3.26.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.fusesource.jansi:jansi:2.4.1=testCompileClasspath,testRuntimeClasspath
|
||||
org.graalvm.sdk:graal-sdk:23.0.2=compileClasspath,default,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.graalvm.truffle:truffle-api:23.0.2=compileClasspath,default,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.jetbrains.intellij.deps:trove4j:1.0.20200330=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
|
||||
Reference in New Issue
Block a user