Skip to content

Which errors should be returned by Store implementations? #77

Open

Description

@dominikbraun

Now that the Store interface is available, it should be clarified which and what kind of errors should be returned by its implementations.

Example: AddEdge adds a new edge. Should the store return ErrEdgeAlready exists if the edge already exists, or should the Graph implementation check this in advance and return ErrEdgeAlready itself?

In short: Should a Store only handle technical errors or domain errors, too?

Advantages of only handling technical errors

  • The developer that implements a Store doesn't have to wrap their head around domain problems and focus on the actual storage logic. They don't need to be familiar with the behavior of the graph in edge cases.
  • Separation of concerns: The Store implementation stores data and does nothing else. Everything graph-related happens in the Graph implementations.

Advantages of handling technical and domain errors

  • More control over the behavior of the graph. If it is ok for the user to overwrite existing edges, they just don't return an error in AddEdge if the edge already exists and can safely rely on that.

CC @geoah

Activity

  1. geoah commented on Jan 26, 2023

    @geoah
    Contributor

    I like the idea of the stores only handling technical errors so that the "business logic" of graphs stays in a single place.
    We could even expand further on the separation by splitting out the errors that the stores are expected to return.

    For example: graphs could return ErrEdgeAlreadyExists while stores return ErrStoreEdgeAlreadyExists
    This would allow us to define a set of errors that stores are expected to return, that the graphs can then check and decide if they need to do something about it, or return a "graph" error.

    Happy with both approaches btw, and also happy to update the stores to behave the way you think works better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is neededquestionFurther information is requested

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions