Add error structs to give more information on errors #156
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds the following error structs:
VertexAlreadyExistsError[K, T]
VertexNotFoundError[K]
EdgeAlreadyExistsError[K]
EdgeNotFoundError[K]
VertexHasEdges[K]
EdgeCausesCycleError[K]
This may be breaking if users check
err ==
instead oferrors.Is
for specific errors (such aserr == ErrVertexNotFound
and noterrors.Is(err, ErrVertexNotFound)
. Depending on versioning strategy and definition of a breaking change, this may warrant a new major version.This change also fixes a few issues I found in memoryStore:
AddEdge
did not conform to theStore
interface: "If either vertex doesn't exit, ErrVertexNotFound should be returned for the respective vertex"UpdateEdge
had a data race in which the edge could have changed between thes.Edge
call and the setting of the edges due to not holding onto the lock.CreatesCycle
was not read locking before accessings.inEdges
To let the store handle error cases when it is part of its interface definition,
undirected
anddirected
:AddEdge
don't check the vertices for existenceRemoveEdge
don't check edge existenceAnd a few minor changes I made while I was there:
ListEdges
instead ofAdjacencyMap
forSize
, saves some allocations and another pass through the edges to create the mapundirected
copydirected
'screatesCycle
method to delegate to the store's version for a more performant implementation