Files
gotes/internal/models/note_errors.go

43 lines
854 B
Go

package models
import (
"fmt"
"strings"
)
type ErrEmptyNoteContent struct{}
type ErrEmptyNoteTitle struct{}
type ErrNoteIncomplete struct {
why []error
}
type ErrNoteTitleOverflow struct {
length int
}
func (e *ErrEmptyNoteContent) Error() string {
return "content cannot be empty"
}
func (e *ErrEmptyNoteTitle) Error() string {
return "title cannot be empty"
}
func (e *ErrNoteIncomplete) Error() string {
if len(e.why) == 0 {
panic("ok so if we use this we need to know why it is incomplete")
}
s := make([]string, len(e.why))
for i, err := range e.why {
s[i] = err.Error()
}
return "note incomplete: " + strings.Join(s, " & ")
}
func (e *ErrNoteIncomplete) Unwrap() []error {
return e.why
}
func (e *ErrNoteTitleOverflow) Error() string {
return fmt.Sprintf("title max length %d, %d provided", NoteTitleMaxLength, e.length)
}