Skip to content

return exactly err on cursor decode results - #288

Merged
jiangz222 merged 6 commits into
qiniu:masterfrom
suhli:master
May 25, 2023
Merged

jiangz222 merged 6 commits into
qiniu:masterfrom
suhli:master

Conversation

@suhli

@suhli suhli commented Apr 23, 2023

Copy link
Copy Markdown
Contributor

Comment thread cursor.go Resolved
Comment thread cursor.go Resolved
@jiangz222

jiangz222 commented May 24, 2023 •

Copy link
Copy Markdown
Collaborator

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

suhli commented May 25, 2023 •

Copy link
Copy Markdown
Contributor Author

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

suhli commented May 25, 2023

Copy link
Copy Markdown
Contributor Author

@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

⌂ 换网址