Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShimmerFairy/435176 to your computer and use it in GitHub Desktop.
Save ShimmerFairy/435176 to your computer and use it in GitHub Desktop.
From 9f1be1c0ef3fd0a21a85256ff076622f356f98f9 Mon Sep 17 00:00:00 2001
From: Lue <lue@twigil.drangle.com>
Date: Fri, 11 Jun 2010 16:01:49 -0700
Subject: [PATCH] Fancy Colo[u]red Errors hath come!
[If your terminal supports ANSI, that is :)]
---
src/Perl6/BacktracePrinter.pm | 21 +++++++++++----------
src/builtins/Num.pir | 10 +++++-----
2 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/src/Perl6/BacktracePrinter.pm b/src/Perl6/BacktracePrinter.pm
index 52f2b5c..89ffe26 100644
--- a/src/Perl6/BacktracePrinter.pm
+++ b/src/Perl6/BacktracePrinter.pm
@@ -3,9 +3,10 @@ class Perl6::BacktracePrinter;
# Drives the overall backtrace production process.
method backtrace_for($exception) {
my @backtrace := $exception.backtrace();
+ my @errorprefix := ("Achtung!", "DON'T PANIC!", "Error!", "Attention!", "Oi!", "Errm...", "Owie!", "FAIL");
if self.is_runtime(@backtrace) {
# Runtime error. Start with the error message.
- my $trace := pir::getattribute__pps($exception, 'message');
+ my $trace := "\e[31;1m" ~ @errorprefix[pir::rand__II(7)] ~ " \e[22;31m" ~ pir::getattribute__pps($exception, 'message')~"\e[00m";
# If top frame is 'die' or warn, drop it from the top.
if ~@backtrace[0]<sub> eq '&die' || ~@backtrace[0]<sub> eq '&warn' {
@@ -16,10 +17,10 @@ method backtrace_for($exception) {
# file to the error and be done.
if self.is_warning($exception) {
my $location := @backtrace[0]<annotations>;
- $trace := $trace ~ " at " ~
+ $trace := $trace ~ " at \e[33m" ~
($location<line> ?? 'line ' ~ $location<line> !! '<unknown line>') ~
($location<file> ?? ':' ~ $location<file> !! '' ) ~
- "\n";
+ "\e[00m\n";
return $trace;
}
@@ -35,7 +36,7 @@ method backtrace_for($exception) {
# If we hit the end of the user's code, we're done; emit last
# annotations and say we're in main program body.
if ~$_<sub> eq '!UNIT_START' {
- $trace := $trace ~ self.backtrace_line(0, $cur_annotations);
+ $trace := $trace ~ "\e[34;1m" ~ self.backtrace_line(0, $cur_annotations) ~ "\e[00m";
last;
}
@@ -45,7 +46,7 @@ method backtrace_for($exception) {
# informative line numbers.
if !pir::isnull(pir::getprop__psp('$!p6type', $_<sub>))
|| pir::substr(~$_<sub>, 0, 6) eq '&infix' {
- $trace := $trace ~ self.backtrace_line($_<sub>, $cur_annotations);
+ $trace := $trace ~ "\e[34;1m" ~ self.backtrace_line($_<sub>, $cur_annotations) ~ "\e[00m";
$cur_annotations := 0;
}
}
@@ -53,8 +54,8 @@ method backtrace_for($exception) {
} else {
# For parse time exceptions, we just want the message, with no
# back trace beyond this.
- return "===SORRY!===\n" ~
- pir::getattribute__pps($exception, 'message') ~ "\n";
+ return "\e[41;37;1m===SORRY!===\e[00m\n" ~
+ "\e[31m" ~ pir::getattribute__pps($exception, 'message') ~ "\e[00m\n";
}
}
@@ -78,12 +79,12 @@ method is_warning($exception) {
# Renders one line in the backtrace, using the given sub name and
# annotations set.
method backtrace_line($sub, $location) {
- " in " ~
+ " in \e[22;32m" ~
($sub ?? self.fullname($sub) !! 'main program body') ~
- " at " ~
+ "\e[34;1m at \e[22;33m" ~
($location<line> ?? 'line ' ~ $location<line> !! '<unknown line>' ) ~
($location<file> ?? ':' ~ $location<file> !! '' ) ~
- "\n"
+ "\e[00m\n"
}
# Generates the fully qualified name of the sub.
diff --git a/src/builtins/Num.pir b/src/builtins/Num.pir
index c77a2b7..eeb4563 100644
--- a/src/builtins/Num.pir
+++ b/src/builtins/Num.pir
@@ -231,15 +231,15 @@ finish:
#errors
ERANGE:
- die "DON'T PANIC! The radix is out of range (2..36 only)"
+ die "The radix is out of range (2..36 only)"
EINVALIDCHAR:
- $S0 = concat "DON'T PANIC! Invalid character (", $S0
- $S0 = concat $S0, ")! Please try again :) "
+ $S0 = concat "Invalid character (", $S0
+ $S0 = concat $S0, ")"
die $S0
EBASENOEXP:
- die "DON'T PANIC! You gave us a base for the magnitude, but you forgot the exponent."
+ die "You gave us a base for the magnitude, but you forgot the exponent."
EEXPNOBASE:
- die "DON'T PANIC! You gave us an exponent for the magnitude, but you forgot the base."
+ die "You gave us an exponent for the magnitude, but you forgot the base."
.end
--
1.6.0.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment