Skip to content

Commit e00bbcd

Browse files
chipx86davidt
authored andcommitted
Ensure correct compiler error styling and strip ANSI escape sequences.
The compiler error output that's injected into the page hard-codes a background color of white, but didn't hard-code a corresponding text color. If the page had set a default text color that was too close to white, it would be hard or impossible to read without selecting the text on the page. This change addresses this by hard-coding a text color of black, ensuring it can be read. It also goes a step further and improves the display when dealing with ANSI escape sequences in the error output, making it difficult to read through or copy/paste meaningful results. We now apply a common regex for stripping away any typical ANSI escape sequences we should expect in such output, leaving behind only the plain text content.
1 parent 3c9354d commit e00bbcd

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

pipeline/templates/pipeline/compile_error.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div id="django-pipeline-error-{{package_name}}" class="django-pipeline-error"
2-
style="display: none; border: 2px #DD0000 solid; margin: 1em; padding: 1em; background: white;">
2+
style="display: none; border: 2px #DD0000 solid; margin: 1em; padding: 1em; background: white; color: black;">
33
<h1>Error compiling {{package_type}} package "{{package_name}}"</h1>
44
<p><strong>Command:</strong></p>
55
<pre style="white-space: pre-wrap;">{{command}}</pre>

pipeline/templatetags/pipeline.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import re
23
import subprocess
34

45
from django import template
@@ -109,13 +110,19 @@ def render_compressed_sources(self, package, package_name, package_type):
109110
return method(package, paths, templates=templates)
110111

111112
def render_error(self, package_type, package_name, e):
113+
# Remove any ANSI escape sequences in the output.
114+
error_output = re.sub(
115+
re.compile(r"(?:\x1B[@-_]|[\x80-\x9F])[0-?]*[ -/]*[@-~]"),
116+
"",
117+
e.error_output)
118+
112119
return render_to_string(
113120
"pipeline/compile_error.html",
114121
{
115122
"package_type": package_type,
116123
"package_name": package_name,
117124
"command": subprocess.list2cmdline(e.command),
118-
"errors": e.error_output,
125+
"errors": error_output,
119126
},
120127
)
121128

0 commit comments

Comments
 (0)