@@ -59,12 +59,33 @@ def validatebatch(inputfile, outputfile="", type="vies", lang="en", statusupdate
5959
6060def processcsv (inputfile , outputfile , type , lang , statusupdate ):
6161 try :
62+
63+ # read the file and check if all rows have the same number of columns
64+ with open (inputfile , 'r' ) as f :
65+ first_line = f .readline ().strip ()
66+ # check if the first line is empty
67+ if not first_line :
68+ logger .error ("Input file is empty." )
69+ return 2
70+
71+ delimiter = settings .load_value_from_json_file ("delimiter" )
72+ # check if the first line ends with the delimiter
73+ if first_line .endswith (delimiter ):
74+ logger .error ("First line ends with the delimiter." )
75+ return 5
76+
77+ split_columns = first_line .split (delimiter )
78+ if len (split_columns ) != len (columns ):
79+ logger .error (f"Expected { len (columns )} columns, but found { len (split_columns )} ." )
80+ return 4
81+
6282 # read csv with columns
6383 data = pd .read_csv (
6484 inputfile ,
6585 names = columns ,
6686 delimiter = settings .load_value_from_json_file ("delimiter" ),
6787 )
88+
6889 # create a list to store the results
6990 results = []
7091 # write statistics
@@ -122,6 +143,12 @@ def processxlsx(inputfile, outputfile, type, lang, statusupdate):
122143 try :
123144 # read the input file
124145 data = pd .read_excel (inputfile , usecols = columns )
146+
147+ # check, if all columns are present
148+ for column in columns :
149+ if column not in data .columns :
150+ logger .error (f"Missing column: { column } " )
151+ return 4
125152 # create a list to store the results
126153 results = []
127154 # write statistics
0 commit comments