Skip to content
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

Panic With ObjectIdHex(s string) #402

Open
zjzjzjzj1874 opened this issue May 11, 2022 · 0 comments
Open

Panic With ObjectIdHex(s string) #402

zjzjzjzj1874 opened this issue May 11, 2022 · 0 comments

Comments

@zjzjzjzj1874
Copy link

It is very danger with mgo/bson/bson.go.212,see code;
if anyone else who wanted to change request args to mongoDB objectID, the code maybe like this:

objID := bson.ID
if IsObjectIdHex(req.ObjectID) {
    objID = ObjectIdHex(req.ObjectID)
}else {
    // TODO do else logic
}

And Why not add like this:

if objID,err := MaybeObjectIdHex(req.ObjectID);err != nil {
    // TODO add return logic
    return
}

    // TODO do correct logic

Any way, panic in runtime is very unfriendly for every programmer.

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

No branches or pull requests

1 participant