summaryrefslogtreecommitdiffstats
path: root/modules/log/errors.go
blob: 942639a434449c469abc3e2dfbcd4de764332c7c (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
// Copyright 2019 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package log

import "fmt"

// ErrTimeout represents a "Timeout" kind of error.
type ErrTimeout struct {
	Name     string
	Provider string
}

// IsErrTimeout checks if an error is a ErrTimeout.
func IsErrTimeout(err error) bool {
	if err == nil {
		return false
	}
	_, ok := err.(ErrTimeout)
	return ok
}

func (err ErrTimeout) Error() string {
	return fmt.Sprintf("Log Timeout for %s (%s)", err.Name, err.Provider)
}

// ErrUnknownProvider represents a "Unknown Provider" kind of error.
type ErrUnknownProvider struct {
	Provider string
}

// IsErrUnknownProvider checks if an error is a ErrUnknownProvider.
func IsErrUnknownProvider(err error) bool {
	if err == nil {
		return false
	}
	_, ok := err.(ErrUnknownProvider)
	return ok
}

func (err ErrUnknownProvider) Error() string {
	return fmt.Sprintf("Unknown Log Provider \"%s\" (Was it registered?)", err.Provider)
}

// ErrDuplicateName represents a Duplicate Name error
type ErrDuplicateName struct {
	Name string
}

// IsErrDuplicateName checks if an error is a ErrDuplicateName.
func IsErrDuplicateName(err error) bool {
	if err == nil {
		return false
	}
	_, ok := err.(ErrDuplicateName)
	return ok
}

func (err ErrDuplicateName) Error() string {
	return fmt.Sprintf("Duplicate named logger: %s", err.Name)
}