From: Mischa POSLAWSKY
Date: Thu, 30 Mar 2017 13:15:01 +0000 (+0200)
Subject: common: common Alert function to format error messages
X-Git-Tag: v1.10~273
X-Git-Url: http://git.shiar.net/sheet.git/commitdiff_plain/b97ebd969b2e520d3e65509c0f892edacae70520?ds=inline
common: common Alert function to format error messages
Technical details in 2nd argument only shown in dev environment.
---
diff --git a/charset.plp b/charset.plp
index fcd647d..d3b27b5 100644
--- a/charset.plp
+++ b/charset.plp
@@ -66,7 +66,7 @@ my @request = map {
$row{table} = ' ' x 1024;
$row{set} = 'Unicode planes';
$row{cell} = do 'charset-ucplanes.inc.pl'
- or printf "Table data could not be read: %s.
\n", $@ || $!;
+ or Alert('Table data could not be read', $@ || $!);
@nibble = (map { $_.0, $_.8 } 0 .. 7);
$nibsize = 8;
}
@@ -75,20 +75,20 @@ my @request = map {
$row{table} = ' ' x ($endpoint < 255 ? 640 : 8192);
$row{set} = 'Unicode BMP';
$row{cell} = do 'charset-unicode.inc.pl'
- or printf "Table data could not be read: %s.
\n", $@ || $!;
+ or Alert('Table data could not be read', $@ || $!);
}
elsif ($row{set} eq 'utf-8-strict') {
$row{table} = undef;
$row{set} = 'UTF-8';
$row{cell} = do 'charset-utf8.inc.pl'
- or printf "Table data could not be read: %s.
\n", $@ || $!;
+ or Alert('Table data could not be read', $@ || $!);
}
else {
$row{table} = Encode::decode($row{set}, pack 'C*', $row{offset} .. $endpoint);
}
}
else {
- say "Encoding $input
unknown
";
+ Alert("Encoding $input
unknown");
}
$row{set} ? \%row : ();
}
diff --git a/common.inc.plp b/common.inc.plp
index 81f91b5..e4cc5f9 100644
--- a/common.inc.plp
+++ b/common.inc.plp
@@ -10,9 +10,15 @@ use File::stat 'stat';
use HTTP::Date;
use Encode qw( decode_utf8 );
+sub Alert {
+ my ($title, $debug) = @_;
+ $title .= ": $debug" if $Dev and defined $debug;
+ say "$title
\n";
+}
+
$PLP::ERROR = sub {
my ($text, $html) = @_;
- print 'Fatal error: '.$html."
\n\n";
+ Alert("Fatal error: $html.");
warn $text;
};
diff --git a/latin.plp b/latin.plp
index 9dd8fe9..529b334 100644
--- a/latin.plp
+++ b/latin.plp
@@ -48,7 +48,7 @@ and common chars.
<:
my @table = do 'writing-latn.inc.pl';
if ($! or $@) {
- printf "Table data not found: %s.
\n", $@ || $!;
+ Alert("Table data not found", $@ || $!);
}
else {
say '