Docs / ArchitectureKit / Fundamentals / Handling Errors

Handling Errors

Every error ArchitectureKit returns belongs to one of four categories. Use errors.Is to check for a category rather than for a concrete error:

  • ErrDomain means that a business rule rejected the command, as with NewDomainError.
  • ErrConflict means that a precondition did not hold.
  • ErrTransient means that trying again may help, for example if reading from the database failed.
  • ErrPermanent means that trying again will not help, for example if an event could not be decoded, or if a subject contains an event type the state has no Evolve rule for.
writtenEvents, err := architecturekit.Execute(
  // ...
)

switch {
case errors.Is(err, architecturekit.ErrDomain):
  // A business rule rejected the command.
case errors.Is(err, architecturekit.ErrConflict):
  // A precondition did not hold.
case errors.Is(err, architecturekit.ErrTransient):
  // Trying again may help.
case errors.Is(err, architecturekit.ErrPermanent):
  // Trying again will not help.
}

Note that ErrConflict is a special case of ErrTransient, so check for it first.

Note that Execute does not retry. To try again, for example after a conflict, call Execute again.