]> git.donarmstrong.com Git - bin.git/commitdiff
error out on malformed lines if necessary
authorDon Armstrong <don@donarmstrong.com>
Mon, 28 Mar 2016 22:04:02 +0000 (15:04 -0700)
committerDon Armstrong <don@donarmstrong.com>
Mon, 28 Mar 2016 22:04:02 +0000 (15:04 -0700)
make_invoice

index 5f87df414c6758c2dbdaae96a216eba74f718814..0047d45079b0544e92a4c1121489629ad1c55a02 100755 (executable)
@@ -176,6 +176,7 @@ while (<$log_fh>) {
      chomp;
      next if /^Total: \d+\.\d{2}$/;
      if (/^\s*\* /) {
+         print STDERR $_."\n";
          if (defined $time) {
               $tex_log .= format_events(date => $date,
                                         date2 => $date2,
@@ -188,13 +189,19 @@ while (<$log_fh>) {
          }
           s/\s*\[[\.\d]+\]\s*\[[\.\d]+\]\s*$//;
          my ($d1,$d2);
-          if (/\s*\*\s*CLOCK:\s+\[([^\]]+)\]--\[([^\]]+)\]/) {
+         if (/\s*\*\s*CLOCK:\s+\[([^\]]+)\]--\[([^\]]+)\]/ or
+             /^\s*\*\s*(.+)?\s* - \s*(.+)?\s*$/
+            ) {
               $d1 = UnixDate(ParseDate($1),'%s');
               $d2 = UnixDate(ParseDate($2),'%s');
+              if (not defined $d1) {
+                  die "Invalid date: $1";
+              }
+              if (not defined $d2) {
+                  die "Invalid date: $2";
+              }
           } else {
-              ($d1,$d2) = map {s/^\s*\*\s*//;
-                               UnixDate(ParseDate($_),'%s')
-                           } split /\s*-\s*/;
+              die "malformed line $_";
           }
           my $string = '* '.strftime('%A, %B %e, %H:%M:%S',localtime($d1)).' - '.
               strftime('%A, %B %e, %H:%M:%S',localtime($d2));