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.Isfor specific errors (such aserr == ErrVertexNotFoundand 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:
AddEdgedid not conform to theStoreinterface: "If either vertex doesn't exit, ErrVertexNotFound should be returned for the respective vertex"UpdateEdgehad a data race in which the edge could have changed between thes.Edgecall and the setting of the edges due to not holding onto the lock.CreatesCyclewas not read locking before accessings.inEdgesTo let the store handle error cases when it is part of its interface definition,
undirectedanddirected:AddEdgedon't check the vertices for existenceRemoveEdgedon't check edge existenceAnd a few minor changes I made while I was there:
ListEdgesinstead ofAdjacencyMapforSize, saves some allocations and another pass through the edges to create the mapundirectedcopydirected'screatesCyclemethod to delegate to the store's version for a more performant implementation