Skip to content

Add ExpectArrayLen / ReadFixedArray #1508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
vmihailenco opened this issue Sep 24, 2020 · 3 comments
Closed

Add ExpectArrayLen / ReadFixedArray #1508

vmihailenco opened this issue Sep 24, 2020 · 3 comments

Comments

@vmihailenco
Copy link
Collaborator

func (r *Reader) ReadFixedArray(caller string, n int) error {
	got, err := r.ReadArrayLen()
	if err != nil {
		return err
	}
	if n != got {
		return fmt.Errorf("redis: %s: unexpected array length; want %d, got %d", caller, n, got)
	}
	return nil
}
@icholy
Copy link
Contributor

icholy commented Sep 24, 2020

I was thinking about the lack of context information in the error too. My reasoning for leaving it out is that it's not something that should ever happen. When you hit this error, it indicates a bug in the library (not user code). An incorrect number of array elements is no different than trying to read an int reply instead of a string reply. Yet those methods also don't have a "caller" parameter. If we want to add context to the error, we should do it consistently further up the call chain.

@vmihailenco
Copy link
Collaborator Author

vmihailenco commented Sep 25, 2020

It is a bug in the library and users will report it here. Without context I have no idea where it happens...

@vmihailenco
Copy link
Collaborator Author

Fixed by #1739

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants