aboutsummaryrefslogtreecommitdiff
path: root/lib/Config.pm6
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2017-04-24 11:12:08 +0200
committerPatrick Spek <p.spek@tyil.nl>2017-04-24 11:12:08 +0200
commitb01a053e3d4012064a667745634010dd654b4777 (patch)
treeed702ba420a3cda7f39f0b6b249b294f02dca487 /lib/Config.pm6
parentede6b8c4cfac8c5eed668ba8357f9e8b11ccbc43 (diff)
Update exceptions with more meaningful messages
Diffstat (limited to 'lib/Config.pm6')
-rw-r--r--lib/Config.pm624
1 files changed, 19 insertions, 5 deletions
diff --git a/lib/Config.pm6 b/lib/Config.pm6
index 4078d73..2fa01bf 100644
--- a/lib/Config.pm6
+++ b/lib/Config.pm6
@@ -2,7 +2,7 @@
use v6.c;
-use Config::Exception::UnsupportedTypeException;
+use Config::Exception::MissingParserException;
use Config::Exception::UnknownTypeException;
use Config::Exception::FileNotFoundException;
use Config::Type;
@@ -48,7 +48,9 @@ class Config is export
my $type = self.get-parser-type($path);
- Config::Exception::UnknownTypeException.new.throw() if $type eq Config::Type::unknown;
+ Config::Exception::UnknownTypeException.new(
+ type => $type
+ ).throw() if $type eq Config::Type::unknown;
"Config::Parser::" ~ $type;
}
@@ -91,12 +93,24 @@ class Config is export
multi method read(Str $path, Str $parser = "")
{
- Config::Exception::FileNotFoundException.new.throw() unless $path.IO.f;
+ Config::Exception::FileNotFoundException.new(
+ path => $path
+ ).throw() unless $path.IO.f;
$!parser = self.get-parser($path, $parser);
- require ::($!parser);
- $!content = ::($!parser).read($path);
+ try {
+ CATCH {
+ when X::CompUnit::UnsatisfiedDependency {
+ Config::Exception::MissingParserException.new(
+ parser => $parser
+ ).throw();
+ }
+ }
+
+ require ::($!parser);
+ $!content = ::($!parser).read($path);
+ }
return True;
}