The RemoveEgde function throws "Key not found" error while trying to remove an edge a->b if there exist no edges with a as their source. This is happening due to the following code:
item, err := txn.Get([]byte(from))
if err != nil {
return err
}
where we are not checking if the error returned by badger is ErrKeyNotFound as is being done for the AddEdge function
Modify the RemoveEdge function to return (bool, error) instead of just a error where bool signifies whether the Remove actually removed an edge or whether it silently failed because the edge didn't exist.
Have the function return:
true, nil on successful removal of an edge that exists
false, nil if the edge doesn't exist
false, error if there is any error
Note that you will have to check for the edge not existing is 2 places: while getting the edgelist for the src node from badger, and then again in the edgelist before calling delete(dstNodes, to)
You are also required to add a unit test to cover this case
The above change is a breaking change to the RemoveEdge API. Make sure to edit all the calls to RemoveEdge in lib_test.go to reflect that
psst, remember to update the usage guide in the README too 👀
The
RemoveEgdefunction throws "Key not found" error while trying to remove an edgea->bif there exist no edges withaas their source. This is happening due to the following code:where we are not checking if the error returned by badger is
ErrKeyNotFoundas is being done for theAddEdgefunctionModify the
RemoveEdgefunction to return(bool, error)instead of just aerrorwhereboolsignifies whether the Remove actually removed an edge or whether it silently failed because the edge didn't exist.Have the function return:
true, nilon successful removal of an edge that existsfalse, nilif the edge doesn't existfalse, errorif there is any errorNote that you will have to check for the edge not existing is 2 places: while getting the edgelist for the src node from badger, and then again in the edgelist before calling
delete(dstNodes, to)You are also required to add a unit test to cover this case
The above change is a breaking change to the
RemoveEdgeAPI. Make sure to edit all the calls toRemoveEdgeinlib_test.goto reflect thatpsst, remember to update the usage guide in the README too 👀