aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2020-07-04 18:49:00 +0200
committerPatrick Spek <p.spek@tyil.nl>2020-07-04 18:49:00 +0200
commit2bdb4e5bd4a7f8570a985685538d1e7187e5c6f8 (patch)
tree60bbf8f195c072c9ae2190b8d83ebdb0fe32a230
parentace67806e8960167349d21ceb0f1acd5e3ca0c11 (diff)
downloadDist::Maker-2bdb4e5bd4a7f8570a985685538d1e7187e5c6f8.tar.gz
Dist::Maker-2bdb4e5bd4a7f8570a985685538d1e7187e5c6f8.tar.bz2
Prettify the error on missing templates
-rw-r--r--META6.json1
-rw-r--r--lib/App/Rakumod/Util.rakumod25
-rw-r--r--lib/X/App/Rakumod/MissingTemplate.rakumod44
3 files changed, 65 insertions, 5 deletions
diff --git a/META6.json b/META6.json
index 6b589fc..3a7d4c7 100644
--- a/META6.json
+++ b/META6.json
@@ -26,6 +26,7 @@
"X::App::Rakumod::Clobber": "lib/X/App/Rakumod/Clobber.rakumod",
"X::App::Rakumod::DuplicateDependency": "lib/X/App/Rakumod/DuplicateDependency.rakumod",
"X::App::Rakumod::DuplicateProvide": "lib/X/App/Rakumod/DuplicateProvide.rakumod",
+ "X::App::Rakumod::MissingTemplate": "lib/X/App/Rakumod/MissingTemplate.rakumod",
"X::App::Rakumod::NoDistribution": "lib/X/App/Rakumod/NoDistribution.rakumod",
"rakumod": "bin/rakumod"
},
diff --git a/lib/App/Rakumod/Util.rakumod b/lib/App/Rakumod/Util.rakumod
index f0dad85..91b8ef3 100644
--- a/lib/App/Rakumod/Util.rakumod
+++ b/lib/App/Rakumod/Util.rakumod
@@ -5,6 +5,8 @@ use v6.d;
use IO::Path::XDG;
use Template::Mustache;
+use X::App::Rakumod::MissingTemplate;
+
unit module App::Rakumod::Util;
sub rakumod-prompt (
@@ -51,12 +53,25 @@ sub rakumod-template (
return $user-template if $user-template.f;
# Check for App::Rakumod default template
- if (%?RESOURCES{"templates/$name"}.IO.f) {
- return %?RESOURCES{"templates/$name"}.IO;
+ try {
+ CATCH {
+ when X::Method::NotFound {
+ # Template could not be found. Even though the
+ # thrown exception is X::Method::NotFound, this
+ # triggers only because .IO is called on a
+ # nonexisting resource. Sadly, there's no good
+ # way to check for the existence of a resource.
+ X::App::Rakumod::MissingTemplate.new(
+ path => $name,
+ user-path => $user-template,
+ ).throw;
+ }
+ }
+
+ if (%?RESOURCES{"templates/$name"}.IO.f) {
+ return %?RESOURCES{"templates/$name"}.IO;
+ }
}
-
- # Template could not be found
- fail("No template found for $name, have you created a template file at $user-template?");
}
sub rakumod-template-render (
diff --git a/lib/X/App/Rakumod/MissingTemplate.rakumod b/lib/X/App/Rakumod/MissingTemplate.rakumod
new file mode 100644
index 0000000..d3bf6ec
--- /dev/null
+++ b/lib/X/App/Rakumod/MissingTemplate.rakumod
@@ -0,0 +1,44 @@
+#!/usr/bin/env false
+
+use v6.d;
+
+use App::Rakumod::Exception;
+
+unit class X::App::Rakumod::MissingTemplate does App::Rakumod::Exception;
+
+#| The relative path of the Template.
+has $.path;
+
+#| The absolute path to the (optional) user-defined template.
+has $.user-path;
+
+method code () { 6 }
+
+method message () {
+ "No template found for $!path, have you created a template file at $!user-path?"
+}
+
+=begin pod
+
+=NAME X::App::Rakumod::MissingTemplate
+=VERSION 0.0.0
+=AUTHOR Patrick Spek <p.spek@tyil.work>
+
+=begin LICENSE
+Copyright © 2020
+
+This program is free software: you can redistribute it and/or modify it under
+the terms of the GNU Affero General Public License as published by the Free
+Software Foundation, version 3.
+
+This program is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License along
+with this program. If not, see &lt;https://www.gnu.org/licenses/&gt;
+=end LICENSE
+
+=end pod
+
+# vim: ft=raku noet sw=8 ts=8