pelican/internal/board/errors.go
Dan Anglin 4e7eb77583
All checks were successful
/ test (pull_request) Successful in 40s
/ lint (pull_request) Successful in 43s
fix: add restrictions when setting IDs.
Main change:

Add restrictions when adding IDs for cards and statuses. Errors are
returned when an attempt is made to set an ID lower than 1, or an
attempt is made to set an ID that has already been set.

Additional changes:

- Error types in the board packages are now defined in errors.go.
- Small formatting to error messages.
2024-01-21 15:39:51 +00:00

53 lines
1.4 KiB
Go

package board
import "fmt"
// CardNotExistError is returned when a card does not exist in the database.
type CardNotExistError struct {
ID int
}
func (e CardNotExistError) Error() string {
return fmt.Sprintf("card ID '%d' does not exist in the database", e.ID)
}
// InvalidIDError is an error for when an attempt to set an ID lower than 1 is made.
type InvalidIDError struct {
ID int
}
func ( e InvalidIDError) Error() string {
return fmt.Sprintf("'%d' is an invalid ID", e.ID)
}
// IDAlreadySetError is an error for when an attempt is made to set an ID that has already been set.
type IDAlreadySetError struct {}
func (e IDAlreadySetError) Error() string {
return "the item's ID is already set"
}
// StatusListEmptyError is an error for unexpected empty list of statuses.
type StatusListEmptyError struct{}
func (e StatusListEmptyError) Error() string {
return "the status list must not be empty"
}
// StatusNotExistError is an error for when a status cannot be found in the database.
type StatusNotExistError struct {
ID int
}
func (e StatusNotExistError) Error() string {
return fmt.Sprintf("status ID '%d' does not exist in the database", e.ID)
}
// StatusNotEmptyError is an error for when an attempt is made to delete non-empty statuses.
type StatusNotEmptyError struct {
ID int
}
func (e StatusNotEmptyError) Error() string {
return fmt.Sprintf("status ID '%d' must contain no cards before deletion", e.ID)
}