JBAS-1426 Classroom cards generator improve error handling
authorBill Erickson <berickxx@gmail.com>
Fri, 20 May 2016 18:18:14 +0000 (11:18 -0700)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/utility-scripts/import_students/classroom_cards/tools/classroom-cards-generator.pl

index 7414f6e..a162bd1 100755 (executable)
@@ -9,6 +9,7 @@
 use strict; use warnings;
 use Text::CSV;
 my $default_dob = '1900-01-01';
+my @required = qw/first_given_name family_name street1 city post_code/;
 
 my $csv_file = $ARGV[0] or die "School info CSV file required\n";
 
@@ -35,6 +36,13 @@ print "action,student_id,first_given_name,".
 my $student_id = 0;
 while (my $school = $csv->getline_hr($fh)) {
 
+    for my $field (@required) {
+        next if $school->{$field};
+        warn "\n===\nMissing value for required field: $field\n===\n";
+        warn $_ . " => " . ($school->{$_} || '') . "\n" for @required;
+        exit 1;
+    }
+
     for my $idx (0..49) {
         print sprintf("C,%04d,%s,%s,%s,%s,%s,%s,%s\n",
             $student_id++,