Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions mongo/gridfs/download_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ func (ds *DownloadStream) fillBuffer(ctx context.Context) error {
_ = ds.cursor.Close(ctx)
return ds.cursor.Err()
}
// If there are no more chunks, but we didn't read the expected number of chunks, return an
// ErrWrongIndex error to indicate that we're missing chunks at the end of the file.
if ds.expectedChunk != ds.numChunks {
return ErrWrongIndex
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between ErrWrongIndex and ErrWrongSize?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our documentation says:

// ErrWrongIndex is used when the chunk retrieved from the server does not have the expected index.
...
// ErrWrongSize is used when the chunk retrieved from the server does not have the expected size.

ErrWrongIndex seems more accurate in this situation than ErrWrongSize. I could also see an argument for a new error type, something like ErrMissingChunks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the error name/description is kinda confusing and an ErrMissingChunk would be more clear. However, since it's caused by the same issue where ErrWrongIndex is currently used (i.e. a chunk is missing), I decided it was better to use the same error so any existing error checking code would continue working.

I originally decided to use ErrWrongIndex because the unified spec test describing the error it's expecting as "ChunkIsMissing". In the Go Driver, there isn't a "ChunkIsMissing" error, but the current spec test runner maps "ChunkIsMissing" to ErrWrongIndex.

I think we should use ErrWrongIndex in both cases, but maybe we can/should update the error message? Something like:

chunk is missing or index does not match expected index

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using ErrWrongIndex SGTM, but I'm hesitant to change the message for ErrWrongIndex in case users are checking for the current message. That said, GridFS does not get much usage, and most users would probably do something like errors.Is(err, gridfs.ErrWrongIndex), anyway, so up to you.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave it as-is and add a proposal to the Go Driver 2.0 scope to rename and/or update the description of the error.

}
return errNoMoreChunks
}

Expand Down
Loading