modernice / goes

goes is an event-sourcing framework for Go.
https://goes.modernice.dev
Apache License 2.0
134 stars 12 forks source link

Add `aggregate.IsConsistencyError` #20

Closed bounoable closed 2 years ago

bounoable commented 2 years ago

MongoDB event store implements its own VersionError and a IsConsistencyError() function. Aggregates that implement repository.Retryer must use the MongoDB-specific function if the MongoDB event store is used. There should be a single aggregate.IsConsistencyError function to check for consistency errors. Implementation-specific errors can then provide a function to tell the aggregate.IsConsistencyError() function if the error is a consistency error.

package mongo

type VersionError struct { ... }

func (err VersionError) IsConsistencyError() bool {
  return true
}
package example

func example() {
  var err mongo.VersionError
  aggregate.IsConsistencyError(err) == true

  var err aggregate.ConsistencyError
  aggregate.IsConsistencyError(err) == true
}
bounoable commented 2 years ago

repository.Retryer.RetryUse() can then return a single value because we can just use the aggregate.IsConsistencyError() function to check if the operation should be retried.