-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwarning.go
More file actions
91 lines (75 loc) · 2.57 KB
/
Copy pathwarning.go
File metadata and controls
91 lines (75 loc) · 2.57 KB
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
/* -----------------------------------------------------------------
* L o r d O f S c r i p t s (tm)
* Copyright (C)2025 Dídimo Grimaldo T.
* GoÜBRU
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Go Bulk Rename & Rename Workflow Utility
*-----------------------------------------------------------------*/
package carousel
import "fmt"
/* ----------------------------------------------------------------
* G l o b a l s
*-----------------------------------------------------------------*/
// These are numeric error codes
const (
WarnEmpty WarningCode = iota
WarnAuthorizationDenied
)
/* ----------------------------------------------------------------
* T y p e s
*-----------------------------------------------------------------*/
type WarningCode int
/**
* Although the Warning object fulfills the Errors interface, it is
* NOT an error, it is simply a warning that could be shown to the
* user but does NOT warrant termination of the application NOR
* termination of the current task.
*/
type Warning struct {
warnum WarningCode
message string
location string
}
/* ----------------------------------------------------------------
* C o n s t r u c t o r s
*-----------------------------------------------------------------*/
func NewWarning(num WarningCode, err error) *Warning {
return &Warning{num, err.Error(), ""}
}
func NewWarningMsg(num WarningCode, message string) *Warning {
return &Warning{num, message, ""}
}
func NewWarningWith(num WarningCode, message string, err error) *Warning {
return &Warning{num, fmt.Sprintf("%s: %s", message, err.Error()), ""}
}
func NewWarningf(num WarningCode, format string, v ...any) *Warning {
return &Warning{num, fmt.Sprintf(format, v...), ""}
}
func IsWarning(err error) bool {
_, ok := err.(*Warning)
return ok
}
/* ----------------------------------------------------------------
* P u b l i c M e t h o d s
*-----------------------------------------------------------------*/
/**
* Implement Error interface
*/
func (e *Warning) Error() string {
var locStr string = ""
if len(e.location) > 0 {
locStr = fmt.Sprintf(" @{%s} ", e.location)
}
return fmt.Sprintf("(Warning) #W%03d%s%s", e.warnum, locStr, e.message)
}
/**
* Set location of error.
* err := NewAesGcmError(14, "Bad thing happened").At("module")
*/
func (e *Warning) At(location string) *Warning {
e.location = location
return e
}
func (e *Warning) Pretty() string {
return fmt.Sprintf("\t(Warning)\n\tNumber: #W%03d\n\tMessage: %s\n\tLocation: %s\n", e.warnum, e.message, e.location)
}