Merge pull request #6445 from CartoDB/6403-improve_empty_csv_handling

Improve empty CSV files handling
pull/6439/head^2
Rafa de la Torre 9 years ago
commit eba9d2f1c0

@ -40,8 +40,8 @@ module CartoDB
source: ERROR_SOURCE_USER
},
1005 => {
title: 'Zero byte file',
what_about: "The file appears to have no information. Double check using a local tool such as QGIS that the file is indeed correct. If everything appears fine, try uploading it again or <a href='mailto:support@cartodb.com?subject=Zero byte file'>contact us</a>.",
title: 'Empty file',
what_about: "The file appears to have no processable information. Double check that the file is indeed correct and it contains supported data. If everything appears fine, try uploading it again or <a href='mailto:support@cartodb.com?subject=Empty file'>contact us</a>.",
source: ERROR_SOURCE_USER
},
1006 => {

@ -169,7 +169,9 @@ module CartoDB
end
def single_column?
::CSV.parse(first_line, csv_options).first.length < 2
columns = ::CSV.parse(first_line, csv_options)
raise EmptyFileError.new if !columns.any?
columns.first.length < 2
end
def multiple_column(row)
@ -208,8 +210,9 @@ module CartoDB
def first_line
return @first_line if @first_line
stream.rewind
@first_line ||= stream.gets
@first_line ||= stream.gets || ''
stream.rewind
@first_line
end
def release

@ -9,7 +9,7 @@ include CartoDB::Importer2::Doubles
describe CartoDB::Importer2::CsvNormalizer do
BUG_COLUMNS_WRONG_SPLIT_FIXTURE_FILE = "#{File.dirname(__FILE__)}/bug_columns_wrong_split.csv"
describe '#run' do
it 'transforms the file using a proper comma delimiter' do
fixture = tab_delimiter_factory
@ -21,6 +21,16 @@ describe CartoDB::Importer2::CsvNormalizer do
csv.run
csv.delimiter.should eq ','
end
it 'raise if detects an empty file' do
fixture = empty_file_factory
csv = CartoDB::Importer2::CsvNormalizer.new(fixture, Log.new)
expect {
csv.run
}.to raise_exception CartoDB::Importer2::EmptyFileError
FileUtils.rm(fixture)
end
end
describe '#detect_delimiter' do
@ -215,6 +225,14 @@ describe CartoDB::Importer2::CsvNormalizer do
filepath
end
def empty_file_factory
filepath = get_temp_csv_fullpath
FileUtils.touch(filepath)
filepath
end
def quoted_string_with_delimiter_factory
filepath = get_temp_csv_fullpath

Loading…
Cancel
Save