Add color to error formatting (#746)

* Add color to error formatting

* Apply suggestions from code review

Co-authored-by: Daniel Chao <daniel.h.chao@gmail.com>

* Address reviewer comments

* Apply suggestions from code review

Co-authored-by: Daniel Chao <daniel.h.chao@gmail.com>

* Define style choices as operations on formatter (abandon semantic API)

* Adjust margin styling

* Review feedback

* Documentation nits

---------

Co-authored-by: Daniel Chao <daniel.h.chao@gmail.com>
This commit is contained in:
Philip K.F. Hölzenspies
2024-11-01 10:02:19 +00:00
committed by GitHub
parent e217cfcd6f
commit 03462fefae
38 changed files with 445 additions and 114 deletions
@@ -31,6 +31,7 @@ class AnalyzerTest {
private val simpleAnalyzer =
Analyzer(
StackFrameTransformers.defaultTransformer,
false,
SecurityManagers.defaultManager,
listOf(ModuleKeyFactories.file, ModuleKeyFactories.standardLibrary, ModuleKeyFactories.pkg),
null,
@@ -108,6 +109,7 @@ class AnalyzerTest {
val analyzer =
Analyzer(
StackFrameTransformers.defaultTransformer,
false,
SecurityManagers.defaultManager,
listOf(ModuleKeyFactories.file, ModuleKeyFactories.standardLibrary, ModuleKeyFactories.pkg),
tempDir.resolve("packages"),
@@ -177,6 +179,7 @@ class AnalyzerTest {
val analyzer =
Analyzer(
StackFrameTransformers.defaultTransformer,
false,
SecurityManagers.defaultManager,
listOf(
ModuleKeyFactories.file,
@@ -288,6 +291,7 @@ class AnalyzerTest {
val analyzer =
Analyzer(
StackFrameTransformers.defaultTransformer,
false,
SecurityManagers.defaultManager,
listOf(
ModuleKeyFactories.file,
@@ -43,7 +43,8 @@ class ReplServerTest {
null,
null,
"/".toPath(),
StackFrameTransformers.defaultTransformer
StackFrameTransformers.defaultTransformer,
false,
)
@Test
@@ -78,7 +78,7 @@ class ImportsAndReadsParserTest {
assertThrows<VmException> {
ImportsAndReadsParser.parse(moduleKey, moduleKey.resolve(SecurityManagers.defaultManager))
}
assertThat(err.toPklException(StackFrameTransformers.defaultTransformer))
assertThat(err.toPklException(StackFrameTransformers.defaultTransformer, false))
.hasMessage(
"""
–– Pkl Error ––
@@ -65,6 +65,7 @@ class ProjectTest {
mapOf("one" to "1"),
listOf("foo:", "bar:").map(Pattern::compile),
listOf("baz:", "biz:").map(Pattern::compile),
null,
false,
path.resolve("cache/"),
listOf(path.resolve("modulepath1/"), path.resolve("modulepath2/")),
@@ -190,7 +190,9 @@ class StackTraceRendererTest {
}
val loop = StackTraceRenderer.StackFrameLoop(loopFrames, 1)
val frames = listOf(createFrame("bar", 1), createFrame("baz", 2), loop)
val renderedFrames = buildString { renderer.doRender(frames, null, this, "", true) }
val formatter = TextFormatter.create(false)
renderer.doRender(frames, null, formatter, "", true)
val renderedFrames = formatter.toString()
assertThat(renderedFrames)
.isEqualTo(
"""
@@ -19,6 +19,7 @@ evaluatorSettings {
["two"] = "2"
}
moduleCacheDir = "my-cache-dir/"
color = "always"
noCache = false
rootDir = "my-root-dir/"
timeout = 5.min