From f5ac493bbdf269f51ac861e1503c3834dea79b9d Mon Sep 17 00:00:00 2001 From: thiswillbeyourgithub <26625900+thiswillbeyourgithub@users.noreply.github.com> Date: Tue, 16 Sep 2025 14:52:52 +0200 Subject: [PATCH 1/2] feat: crash if template can't be found Signed-off-by: thiswillbeyourgithub <26625900+thiswillbeyourgithub@users.noreply.github.com> --- sanoid | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sanoid b/sanoid index 8e0d186..1e32ecd 100755 --- a/sanoid +++ b/sanoid @@ -1020,6 +1020,12 @@ sub init { $rawtemplate =~ s/\s+$//g; my $template = 'template_'.$rawtemplate; + + # Check if template exists + if (!exists $ini{$template}) { + die "FATAL ERROR: Template '$rawtemplate' referenced in section [$section] does not exist in $conf_file.\n"; + } + foreach my $key (keys %{$ini{$template}}) { if ($key =~ /template|recursive/) { warn "ignored key '$key' from '$rawtemplate' template.\n"; From 88a09b141ee8f60758d4f4f94d268dae9cbcb4d4 Mon Sep 17 00:00:00 2001 From: thiswillbeyourgithub <26625900+thiswillbeyourgithub@users.noreply.github.com> Date: Tue, 16 Sep 2025 15:00:44 +0200 Subject: [PATCH 2/2] feat: crash if found unused templates Signed-off-by: thiswillbeyourgithub <26625900+thiswillbeyourgithub@users.noreply.github.com> --- sanoid | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/sanoid b/sanoid index 1e32ecd..d119574 100755 --- a/sanoid +++ b/sanoid @@ -1145,6 +1145,35 @@ sub init { } } + # Check for unused templates + my %defined_templates; + my %used_templates; + + # Collect all defined templates + foreach my $section (keys %ini) { + if ($section =~ /^template_(.+)$/) { + $defined_templates{$1} = 1; + } + } + + # Collect all used templates + foreach my $section (keys %ini) { + if ($section !~ /^template_/ && defined $ini{$section}{'use_template'}) { + my @templates = split (' *, *', $ini{$section}{'use_template'}); + foreach my $rawtemplate (@templates) { + $rawtemplate =~ s/\s+$//g; # strip trailing whitespace + $used_templates{$rawtemplate} = 1; + } + } + } + + # Check for unused templates (excluding template_default) + foreach my $template (keys %defined_templates) { + if ($template ne 'default' && !exists $used_templates{$template}) { + die "FATAL ERROR: Template '$template' is defined but never used in $conf_file.\n"; + } + } + return %config; } # end sub init