mirror of
https://github.com/mattermost/focalboard.git
synced 2024-12-24 13:43:12 +02:00
158f28ec29
* move gowork app to root build dir * bump versions: mattermost-server, mattermost-plugin-api, opengraph * add go.work to .dockerignore Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
82 lines
1.9 KiB
Go
82 lines
1.9 KiB
Go
package model
|
|
|
|
import (
|
|
"database/sql"
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
|
|
pluginapi "github.com/mattermost/mattermost-plugin-api"
|
|
)
|
|
|
|
// ErrBlocksFromDifferentBoards is an error type that can be returned
|
|
// when a set of blocks belong to different boards.
|
|
var ErrBlocksFromDifferentBoards = errors.New("blocks belong to different boards")
|
|
|
|
// ErrNotFound is an error type that can be returned by store APIs when a query unexpectedly fetches no records.
|
|
type ErrNotFound struct {
|
|
resource string
|
|
}
|
|
|
|
// NewErrNotFound creates a new ErrNotFound instance.
|
|
func NewErrNotFound(resource string) *ErrNotFound {
|
|
return &ErrNotFound{
|
|
resource: resource,
|
|
}
|
|
}
|
|
|
|
func (nf *ErrNotFound) Error() string {
|
|
return fmt.Sprintf("{%s} not found", nf.resource)
|
|
}
|
|
|
|
// IsErrNotFound returns true if `err` is or wraps one of:
|
|
// - model.ErrNotFound
|
|
// - sql.ErrNoRows
|
|
// - mattermost-plugin-api/ErrNotFound.
|
|
func IsErrNotFound(err error) bool {
|
|
if err == nil {
|
|
return false
|
|
}
|
|
|
|
// check if this is a sql.ErrNotFound
|
|
if errors.Is(err, sql.ErrNoRows) {
|
|
return true
|
|
}
|
|
|
|
// check if this is a model.ErrNotFound
|
|
var nf *ErrNotFound
|
|
if errors.As(err, &nf) {
|
|
return true
|
|
}
|
|
|
|
// check if this is a plugin API error
|
|
return errors.Is(err, pluginapi.ErrNotFound)
|
|
}
|
|
|
|
// ErrNotAllFound is an error type that can be returned by store APIs
|
|
// when a query that should fetch a certain amount of records
|
|
// unexpectedly fetches less.
|
|
type ErrNotAllFound struct {
|
|
resources []string
|
|
}
|
|
|
|
func NewErrNotAllFound(resources []string) *ErrNotAllFound {
|
|
return &ErrNotAllFound{
|
|
resources: resources,
|
|
}
|
|
}
|
|
|
|
func (na *ErrNotAllFound) Error() string {
|
|
return fmt.Sprintf("not all instances in {%s} found", strings.Join(na.resources, ", "))
|
|
}
|
|
|
|
// IsErrNotAllFound returns true if `err` is or wraps a ErrNotAllFound.
|
|
func IsErrNotAllFound(err error) bool {
|
|
if err == nil {
|
|
return false
|
|
}
|
|
|
|
var na *ErrNotAllFound
|
|
return errors.As(err, &na)
|
|
}
|