Golang Parsing Csv File, Parse Error: Extraneous Or Missing " in Quoted-field

Updated at: 2020-06-22 Views: 1607 Words: 283 Category: golang

The system for parsing Baidu Statistics CSV logs has been running for almost a month with no problems. But this morning, it suddenly reported the following error.

> import_log /mnt/d/to_del/2020-06-20.csv
2020/06/22 07:55:18 parse error on line 686 , column 60: extraneous or missing " in quoted-field

The corresponding CSV file data behaves similarly to this structure, with the error point in a double quotation mark before "golang".

"515", "2020/06/20 13:07:08", "books "golang" (www)", "Windows 10".

It can be seen that the Baidu CSV file does not escape double quotes.

Where is the error reported?

How do I know which line of golang code is reporting an error?

Does log.Fatal cause the program to exit?

I actually tested that log.Println doesn't cause the program to exit, whereas log.Fatal does.

Checking a document, this is indeed the case.

log.Fatal is equivalent to Print() followed by a call to os.Exit(1).

Then, naturally, one would guess that the log.Fatal line caused the program to exit.

for {
	// Read each record from csv
	record, err := r.Read()
	if err == io.EOF {
		break
	}
	if err ! = nil {
		log.Fatal(err)
	}

	parseRecord(record)
}

Ignore this line

for {
	// Read each record from csv
	record, err := r.Read()
	if err == io.EOF {
		break
	}

	if err ! = nil {
		log.Println(err)
		log.Println("Ignore")
	} else {
		parseRecord(record)
	}
}

Other than ignoring this line of data, what's better solution?

Because the use of double quotation marks is a more common practice in search, double quotation marks mean that the keyword must be included.

The current practice of this omission is very imprecise.

// TODO

Leave a Comment