Skip to content

return exactly err on cursor decode results #288

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

Merged
merged 6 commits into from
May 25, 2023
Merged

return exactly err on cursor decode results #288

merged 6 commits into from
May 25, 2023

Conversation

suhli
Copy link
Contributor

@suhli suhli commented Apr 23, 2023

@jiangz222
Copy link
Collaborator

jiangz222 commented May 24, 2023

Hi @suhli, I checked the implement of cursor.Next(...) in mongo-go-driver, the error is return by

func (c *Cursor) Err() error { return c.err }

And qmgo has function Err() too, so I think you should pass error by Err() with cursor.err, this pr should change codes like:

func (c *Cursor) Next(result interface{}) bool {
......
	if c.cursor.Next(c.ctx) {
		err = c.cursor.Decode(result)
		if err != nil {
			c.err = err
			return false
		}
		return true
	}
......
}

Please share your idea.

@suhli
Copy link
Contributor Author

suhli commented May 25, 2023

Hi @suhli, I checked the implement of cursor.Next(...) in mongo-go-driver, the error is return by

func (c *Cursor) Err() error { return c.err }

And qmgo has function Err() too, so I think you should pass error by Err() with cursor.err, this pr should change codes like:

func (c *Cursor) Next(result interface{}) bool {
......
	if c.cursor.Next(c.ctx) {
		err = c.cursor.Decode(result)
		if err != nil {
			c.err = err
			return false
		}
		return true
	}
......
}

Please share your idea.

sure,and we just do that outside?

...
if !cr.Next(result) {
   if cr.err != nil{
     return cr.err
   }
   return ErrNoSuchDocuments
}
....

@suhli
Copy link
Contributor Author

suhli commented May 25, 2023

@jiangz222 ok,please check the file changes

@jiangz222 jiangz222 merged commit d2c76fd into qiniu:master May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants