summaryrefslogtreecommitdiffstats
path: root/models/quota/errors.go
blob: 962c8b1cca65877d85ddb10400beb6840789f89a (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright 2024 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package quota

import "fmt"

type ErrRuleAlreadyExists struct {
	Name string
}

func IsErrRuleAlreadyExists(err error) bool {
	_, ok := err.(ErrRuleAlreadyExists)
	return ok
}

func (err ErrRuleAlreadyExists) Error() string {
	return fmt.Sprintf("rule already exists: [name: %s]", err.Name)
}

type ErrRuleNotFound struct {
	Name string
}

func IsErrRuleNotFound(err error) bool {
	_, ok := err.(ErrRuleNotFound)
	return ok
}

func (err ErrRuleNotFound) Error() string {
	return fmt.Sprintf("rule not found: [name: %s]", err.Name)
}

type ErrGroupAlreadyExists struct {
	Name string
}

func IsErrGroupAlreadyExists(err error) bool {
	_, ok := err.(ErrGroupAlreadyExists)
	return ok
}

func (err ErrGroupAlreadyExists) Error() string {
	return fmt.Sprintf("group already exists: [name: %s]", err.Name)
}

type ErrGroupNotFound struct {
	Name string
}

func IsErrGroupNotFound(err error) bool {
	_, ok := err.(ErrGroupNotFound)
	return ok
}

func (err ErrGroupNotFound) Error() string {
	return fmt.Sprintf("group not found: [group: %s]", err.Name)
}

type ErrUserAlreadyInGroup struct {
	GroupName string
	UserID    int64
}

func IsErrUserAlreadyInGroup(err error) bool {
	_, ok := err.(ErrUserAlreadyInGroup)
	return ok
}

func (err ErrUserAlreadyInGroup) Error() string {
	return fmt.Sprintf("user already in group: [group: %s, userID: %d]", err.GroupName, err.UserID)
}

type ErrUserNotInGroup struct {
	GroupName string
	UserID    int64
}

func IsErrUserNotInGroup(err error) bool {
	_, ok := err.(ErrUserNotInGroup)
	return ok
}

func (err ErrUserNotInGroup) Error() string {
	return fmt.Sprintf("user not in group: [group: %s, userID: %d]", err.GroupName, err.UserID)
}

type ErrRuleAlreadyInGroup struct {
	GroupName string
	RuleName  string
}

func IsErrRuleAlreadyInGroup(err error) bool {
	_, ok := err.(ErrRuleAlreadyInGroup)
	return ok
}

func (err ErrRuleAlreadyInGroup) Error() string {
	return fmt.Sprintf("rule already in group: [group: %s, rule: %s]", err.GroupName, err.RuleName)
}

type ErrRuleNotInGroup struct {
	GroupName string
	RuleName  string
}

func IsErrRuleNotInGroup(err error) bool {
	_, ok := err.(ErrRuleNotInGroup)
	return ok
}

func (err ErrRuleNotInGroup) Error() string {
	return fmt.Sprintf("rule not in group: [group: %s, rule: %s]", err.GroupName, err.RuleName)
}

type ErrParseLimitSubjectUnrecognized struct {
	Subject string
}

func IsErrParseLimitSubjectUnrecognized(err error) bool {
	_, ok := err.(ErrParseLimitSubjectUnrecognized)
	return ok
}

func (err ErrParseLimitSubjectUnrecognized) Error() string {
	return fmt.Sprintf("unrecognized quota limit subject: [subject: %s]", err.Subject)
}