Skip to content

Commit

Permalink
Ensure correct compiler error styling and strip ANSI escape sequences.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chipx86 authored and davidt committed Apr 17, 2024
1 parent 3c9354d commit e00bbcd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pipeline/templates/pipeline/compile_error.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div id="django-pipeline-error-{{package_name}}" class="django-pipeline-error"
style="display: none; border: 2px #DD0000 solid; margin: 1em; padding: 1em; background: white;">
style="display: none; border: 2px #DD0000 solid; margin: 1em; padding: 1em; background: white; color: black;">
<h1>Error compiling {{package_type}} package "{{package_name}}"</h1>
<p><strong>Command:</strong></p>
<pre style="white-space: pre-wrap;">{{command}}</pre>
Expand Down
9 changes: 8 additions & 1 deletion pipeline/templatetags/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import re
import subprocess

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

def render_error(self, package_type, package_name, e):
# Remove any ANSI escape sequences in the output.
error_output = re.sub(
re.compile(r"(?:\x1B[@-_]|[\x80-\x9F])[0-?]*[ -/]*[@-~]"),
"",
e.error_output)

return render_to_string(
"pipeline/compile_error.html",
{
"package_type": package_type,
"package_name": package_name,
"command": subprocess.list2cmdline(e.command),
"errors": e.error_output,
"errors": error_output,
},
)

Expand Down

0 comments on commit e00bbcd

Please sign in to comment.