...
1 package apperror
2
3 import "runtime"
4
5 type AbortError struct {
6 code int
7 source SourceLocation
8 err error
9 }
10
11 func NewAbortError(err error, code int) *AbortError {
12 var location SourceLocation
13 if _, file, line, ok := runtime.Caller(1); ok {
14 location = SourceLocation{File: file, Line: line}
15 }
16
17 return &AbortError{
18 code: code,
19 source: location,
20 err: err,
21 }
22 }
23
24 func (e AbortError) Error() string {
25 return e.err.Error()
26 }
27
28 func (e AbortError) AbortError() (int, error) {
29 return e.code, e.err
30 }
31
32 func (e AbortError) Unwrap() error {
33 return e.err
34 }
35
36 func (e AbortError) SourceLocation() SourceLocation {
37 return e.source
38 }
39
View as plain text