This repository has been archived by the owner on Mar 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
errors.go
170 lines (134 loc) · 4.75 KB
/
errors.go
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// Copyright 2022-2023 VMware, Inc.
//
// This product is licensed to you under the BSD-2 license (the "License").
// You may not use this product except in compliance with the BSD-2 License.
// This product may include a number of subcomponents with separate copyright
// notices and license terms. Your use of these subcomponents is subject to
// the terms and conditions of the subcomponent's license, as noted in the
// LICENSE file.
//
// SPDX-License-Identifier: BSD-2-Clause
package metadata
import (
"fmt"
)
// Define TUF error types used inside the new modern implementation.
// The names chosen for TUF error types should start in 'Err' except where
// there is a good reason not to, and provide that reason in those cases.
// Repository errors
// ErrRepository - an error with a repository's state, such as a missing file.
// It covers all exceptions that come from the repository side when
// looking from the perspective of users of metadata API or client
type ErrRepository struct {
Msg string
}
func (e ErrRepository) Error() string {
return fmt.Sprintf("repository error: %s", e.Msg)
}
// ErrUnsignedMetadata - An error about metadata object with insufficient threshold of signatures
type ErrUnsignedMetadata struct {
Msg string
}
func (e ErrUnsignedMetadata) Error() string {
return fmt.Sprintf("unsigned metadata error: %s", e.Msg)
}
// ErrUnsignedMetadata is a subset of ErrRepository
func (e ErrUnsignedMetadata) Is(target error) bool {
return target == ErrRepository{} || target == ErrUnsignedMetadata{}
}
// ErrBadVersionNumber - An error for metadata that contains an invalid version number
type ErrBadVersionNumber struct {
Msg string
}
func (e ErrBadVersionNumber) Error() string {
return fmt.Sprintf("bad version number error: %s", e.Msg)
}
// ErrBadVersionNumber is a subset of ErrRepository
func (e ErrBadVersionNumber) Is(target error) bool {
return target == ErrRepository{} || target == ErrBadVersionNumber{}
}
// ErrEqualVersionNumber - An error for metadata containing a previously verified version number
type ErrEqualVersionNumber struct {
Msg string
}
func (e ErrEqualVersionNumber) Error() string {
return fmt.Sprintf("equal version number error: %s", e.Msg)
}
// ErrEqualVersionNumber is a subset of both ErrRepository and ErrBadVersionNumber
func (e ErrEqualVersionNumber) Is(target error) bool {
return target == ErrRepository{} || target == ErrBadVersionNumber{} || target == ErrEqualVersionNumber{}
}
// ErrExpiredMetadata - Indicate that a TUF Metadata file has expired
type ErrExpiredMetadata struct {
Msg string
}
func (e ErrExpiredMetadata) Error() string {
return fmt.Sprintf("expired metadata error: %s", e.Msg)
}
// ErrExpiredMetadata is a subset of ErrRepository
func (e ErrExpiredMetadata) Is(target error) bool {
return target == ErrRepository{} || target == ErrExpiredMetadata{}
}
// ErrLengthOrHashMismatch - An error while checking the length and hash values of an object
type ErrLengthOrHashMismatch struct {
Msg string
}
func (e ErrLengthOrHashMismatch) Error() string {
return fmt.Sprintf("length/hash verification error: %s", e.Msg)
}
// ErrLengthOrHashMismatch is a subset of ErrRepository
func (e ErrLengthOrHashMismatch) Is(target error) bool {
return target == ErrRepository{} || target == ErrLengthOrHashMismatch{}
}
// Download errors
// ErrDownload - An error occurred while attempting to download a file
type ErrDownload struct {
Msg string
}
func (e ErrDownload) Error() string {
return fmt.Sprintf("download error: %s", e.Msg)
}
// ErrDownloadLengthMismatch - Indicate that a mismatch of lengths was seen while downloading a file
type ErrDownloadLengthMismatch struct {
Msg string
}
func (e ErrDownloadLengthMismatch) Error() string {
return fmt.Sprintf("download length mismatch error: %s", e.Msg)
}
// ErrDownloadLengthMismatch is a subset of ErrDownload
func (e ErrDownloadLengthMismatch) Is(target error) bool {
return target == ErrDownload{} || target == ErrDownloadLengthMismatch{}
}
// ErrDownloadHTTP - Returned by Fetcher interface implementations for HTTP errors
type ErrDownloadHTTP struct {
StatusCode int
URL string
}
func (e ErrDownloadHTTP) Error() string {
return fmt.Sprintf("failed to download %s, http status code: %d", e.URL, e.StatusCode)
}
// ErrDownloadHTTP is a subset of ErrDownload
func (e ErrDownloadHTTP) Is(target error) bool {
return target == ErrDownload{} || target == ErrDownloadHTTP{}
}
// ValueError
type ErrValue struct {
Msg string
}
func (e ErrValue) Error() string {
return fmt.Sprintf("value error: %s", e.Msg)
}
// TypeError
type ErrType struct {
Msg string
}
func (e ErrType) Error() string {
return fmt.Sprintf("type error: %s", e.Msg)
}
// RuntimeError
type ErrRuntime struct {
Msg string
}
func (e ErrRuntime) Error() string {
return fmt.Sprintf("runtime error: %s", e.Msg)
}