acmpesuecc / acmpesuecc/Onyx

`RemoveEdge` incorrectly throws error in specific case

Aperta
#1 13 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Bounty: 450 bug good first issue
Lingua principale
Go
Stelle
3
Fork
2
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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:
```go
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_ 👀

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.