title: Go panic: extra delimiter at end of line
body: <p>I'm reading the <a href="http://dev.maxmind.com/geoip/legacy/geolite/" rel="nofollow">MaxMind GeoIP Lite</a> City locations CSV file using Go:</p>
  
  <pre><code>csvFile, err := os.Open("/path/GeoLiteCity_20130702/GeoLiteCity-Location.csv")
  defer csvFile.Close()
  
  if err != nil {
      panic(err)
  }
  
  csvf := csv.NewReader(csvFile)
  csvf.Read()     // skip header row
  
  
  for {
      fields, err := csvf.Read()
  
      if err == io.EOF {
          break
      } else if err != nil {
          panic(err)
      }
  
      // does nothing yet
  }
  </code></pre>
  
  <p>The error I'm getting is:</p>
  
  <blockquote>
    <p>panic: line 2, column 22: extra delimiter at end of line</p>
    
    <p>goroutine 1 [running]: main.main()
      /path/myprogram.go:239
    +0x108f</p>
    
    <p>goroutine 2 [runnable]: exit status 2</p>
  </blockquote>
  
  <p>The file is quite long, but starts with these lines:</p>
  
  <pre><code>locId,country,region,city,postalCode,latitude,longitude,metroCode,areaCode
  1,O1,,,,0.0000,0.0000,,
  2,AP,,,,35.0000,105.0000,,
  3,EU,,,,47.0000,8.0000,,
  4,AD,,,,42.5000,1.5000,,
  5,AE,,,,24.0000,54.0000,,
  6,AF,,,,33.0000,65.0000,,
  7,AG,,,,17.0500,-61.8000,,
  8,AI,,,,18.2500,-63.1667,,
  9,AL,,,,41.0000,20.0000,,
  </code></pre>
  
  <p>It appears to be properly formatted. Each row has 9 fields.</p>
  
  <p>Line 239 is my line invoking the panic, <code>panic(err)</code>. As you can see, it's failing on line 2 of the CSV file, which happens in the first iteration of the loop (line 1 is read before the loop, to skip the header row). Column 22 of line 2 is the second-to-last comma.</p>
  
  <p>Am I missing something here? I don't see any trailing comma... (clarification: the commas at the end of each line must be there to indicate empty field values, so they're not trailing, as in, extra.)</p>
  
  <p><strong>UPDATE:</strong> <a href="https://code.google.com/p/go/issues/detail?id=5892" rel="nofollow">The gophers have resolved this issue and the fix ships with Go 1.1.2</a>.</p>