From 8b78e44bc4b4b4c1aad7e154169c55a5581a785a Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Mon, 18 Jan 2016 10:31:40 -0800 Subject: [PATCH] Create recent alert file if not exists. die()'ing here didn't make much sense. If the file isn't there, we don't have any recent alerts, so an empty file and returning and empty hash fine. Note this doesn't test if the directory is empty. --- conky-mythtv-weather-alert.plx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/conky-mythtv-weather-alert.plx b/conky-mythtv-weather-alert.plx index 9bc356e..20d1044 100755 --- a/conky-mythtv-weather-alert.plx +++ b/conky-mythtv-weather-alert.plx @@ -35,7 +35,12 @@ sub ReadRecentWeatherAlerts ($) { my %info; my $file = File::Spec->catfile($dir, 'conky-weather-alert-recent'); - open(RECENT_ALERTS, "<", $file) or die "unable to open $file for reading: $!"; + unless (open(RECENT_ALERTS, "<", $file)) { + # If the file doesn't exist, create it empty. + warn "unable to open $file for reading: $! (will recreate)"; + WriteRecentWeatherAlerts($dir, {}); + return {}; + } my $key; my $data = ""; foreach my $line () {