Skip to content

RemoveEdge incorrectly throws error in specific case  #1

@Smuzzy-waiii

Description

@Smuzzy-waiii

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 👀

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions