Skip to content

Commit

Permalink
Strip control codes in error messages.
Browse files Browse the repository at this point in the history
This provides clean error messages when webpack runs with --color.
  • Loading branch information
aaugustin committed Jan 24, 2016
1 parent b00bf80 commit 8f45767
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions webpack_loader/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ def filter_files(files, config):
yield F


control_sequence_re = re.compile( # See ECMA 48, 5.4 Control sequences
r'(\x1b\x5b|\x9b)' # Control Sequence Introducer
r'[\x30-\x3f]*' # Parameter Bytes
r'[\x20-\x2f]*' # Intermediate Bytes
r'[\x40-\x7e]' # Final Byte
)


def strip_control_sequences(message):
return control_sequence_re.sub('', message)


def get_bundle(bundle_name, config):
assets = get_assets(config)

Expand All @@ -80,6 +92,7 @@ def get_bundle(bundle_name, config):
elif assets.get('status') == 'error':
if 'file' not in assets:
assets['file'] = ''
assets['message'] = strip_control_sequences(assets['message'])
error = u"""
{error} in {file}
{message}
Expand Down

0 comments on commit 8f45767

Please sign in to comment.