Skip to content

Panic With ObjectIdHex(s string) #402

Description

@zjzjzjzj1874

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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions