aboutsummaryrefslogtreecommitdiff
path: root/IdaliusConfig.pm
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2018-09-23 15:12:33 +1200
committerDavid Phillips <david@sighup.nz>2018-09-23 15:12:33 +1200
commit4dba8e757ed484450e71129fc5966c2512735aea (patch)
tree2fab22e8e91ff0e1f1d8b0d46079720756c3f3f4 /IdaliusConfig.pm
parentbed37697b2fa383344f23ac1f9df52fa2508c30b (diff)
downloadidalius-4dba8e757ed484450e71129fc5966c2512735aea.tar.xz
Improve config error context
Diffstat (limited to 'IdaliusConfig.pm')
-rw-r--r--IdaliusConfig.pm16
1 files changed, 12 insertions, 4 deletions
diff --git a/IdaliusConfig.pm b/IdaliusConfig.pm
index 21c4efa..d51a197 100644
--- a/IdaliusConfig.pm
+++ b/IdaliusConfig.pm
@@ -65,6 +65,14 @@ sub check_config
}
+sub parse_die {
+ my ($supplementary, $from, $to, $line) = @_;
+ my $pad = " " x ($from + 1);
+ my $underline = "^" x ($to - $from + 1);
+
+ die "$supplementary:\n$line\n$pad$underline\n";
+}
+
sub parse_config
{
my $file = $_[0];
@@ -76,12 +84,12 @@ sub parse_config
# Detect list or hash config option
my $c = substr $config->{$section}->{$opt}, 0, 1;
if ($c eq "[") {
- my ($error, @listified) = ListParser::parse_list($config->{$section}->{$opt}, 0);
- die $error if $error;
+ my (($error, $from, $to), @listified) = ListParser::parse_list($config->{$section}->{$opt}, 0);
+ parse_die ($error, $from, $to, $config->{$section}->{$opt}) if $error;
$config->{$section}->{$opt} = \@listified;
} elsif ($c eq "{") {
- my ($error, %hashified) = ListParser::parse_list($config->{$section}->{$opt}, 1);
- die $error if $error;
+ my (($error, $from, $to), %hashified) = ListParser::parse_list($config->{$section}->{$opt}, 1);
+ parse_die ($error, $from, $to, $config->{$section}->{$opt}) if $error;
$config->{$section}->{$opt} = \%hashified;
}
}