aboutsummaryrefslogtreecommitdiffstats
path: root/models/foreignreference/error.go
blob: 07ed1052a63bf9e73816414d15c4939427cfa21e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2022 Gitea. All rights reserved.
// SPDX-License-Identifier: MIT

package foreignreference

import (
	"fmt"

	"code.gitea.io/gitea/modules/util"
)

// ErrLocalIndexNotExist represents a "LocalIndexNotExist" kind of error.
type ErrLocalIndexNotExist struct {
	RepoID       int64
	ForeignIndex int64
	Type         string
}

// ErrLocalIndexNotExist checks if an error is a ErrLocalIndexNotExist.
func IsErrLocalIndexNotExist(err error) bool {
	_, ok := err.(ErrLocalIndexNotExist)
	return ok
}

func (err ErrLocalIndexNotExist) Error() string {
	return fmt.Sprintf("repository %d has no LocalIndex for ForeignIndex %d of type %s", err.RepoID, err.ForeignIndex, err.Type)
}

func (err ErrLocalIndexNotExist) Unwrap() error {
	return util.ErrNotExist
}

// ErrForeignIndexNotExist represents a "ForeignIndexNotExist" kind of error.
type ErrForeignIndexNotExist struct {
	RepoID     int64
	LocalIndex int64
	Type       string
}

// ErrForeignIndexNotExist checks if an error is a ErrForeignIndexNotExist.
func IsErrForeignIndexNotExist(err error) bool {
	_, ok := err.(ErrForeignIndexNotExist)
	return ok
}

func (err ErrForeignIndexNotExist) Error() string {
	return fmt.Sprintf("repository %d has no ForeignIndex for LocalIndex %d of type %s", err.RepoID, err.LocalIndex, err.Type)
}

func (err ErrForeignIndexNotExist) Unwrap() error {
	return util.ErrNotExist
}