aboutsummaryrefslogblamecommitdiffstats
path: root/entity/err.go
blob: 7d6c662e9b544a54389991895f416decef8732cf (plain) (tree)
1
              

























                                                                              




                                         
package entity

import (
	"fmt"
	"strings"
)

type ErrMultipleMatch struct {
	entityType string
	Matching   []Id
}

func NewErrMultipleMatch(entityType string, matching []Id) *ErrMultipleMatch {
	return &ErrMultipleMatch{entityType: entityType, Matching: matching}
}

func (e ErrMultipleMatch) Error() string {
	matching := make([]string, len(e.Matching))

	for i, match := range e.Matching {
		matching[i] = match.String()
	}

	return fmt.Sprintf("Multiple matching %s found:\n%s",
		e.entityType,
		strings.Join(matching, "\n"))
}

func IsErrMultipleMatch(err error) bool {
	_, ok := err.(*ErrMultipleMatch)
	return ok
}