jonas-p / go-shp

Go library for reading and writing ESRI Shapefiles. Pure Golang implementation based on the ESRI Shapefile technical description.
MIT License
255 stars 67 forks source link

Symptom: the shape last shape was not being read #35

Closed leonnemets closed 5 years ago

leonnemets commented 5 years ago

Root Cause: reader.Next was returning false due to an error being reported in r.shape.read(er) error: r.err = fmt.Errorf("Error while reading next shape: %v", er.e)

However the error is wrongly reported by errreader.

Go documentation states that an EOF error may be returned even if all the requested data has been read, but go-shp was treating EOF error as an error even when all the bytes have been read.

Go documentation: https://go.googlesource.com/go/+/master/src/io/io.go#66

// Callers should always process the n > 0 bytes returned before // considering the error err. Doing so correctly handles I/O errors // that happen after reading some bytes and also both of the // allowed EOF behaviors.

errreader.go was giving priority to the err over the number of bytes being read

Note: This behaviour did not manifest itself in every environment. Running locally on Ubuntu, the last shape was being read OK Running on Google App Engine, the last shape was not being read due to this bug

codecov-io commented 5 years ago

Codecov Report

Merging #35 into master will decrease coverage by 0.15%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #35      +/-   ##
==========================================
- Coverage    60.2%   60.04%   -0.16%     
==========================================
  Files           7        7              
  Lines         799      801       +2     
==========================================
  Hits          481      481              
- Misses        262      264       +2     
  Partials       56       56
Impacted Files Coverage Δ
errreader.go 100% <100%> (ø) :arrow_up:
sequentialreader.go 50.87% <0%> (-1.76%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update af2d0c9...0605637. Read the comment docs.

fawick commented 5 years ago

Thank you very much, @leonnemets!