This repository has been archived by the owner on Mar 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
errors.go
76 lines (60 loc) · 1.62 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
/*** Copyright (c) 2016, University of Florida Research Foundation, Inc. and The BioTeam, Inc. ***
*** For more information please refer to the LICENSE.md file ***/
package gorods
// #include "wrapper.h"
import "C"
import (
"fmt"
"time"
"unsafe"
)
// Log level constants
const (
Info = iota
Warn
Fatal
)
// GoRodsError stores information about errors
type GoRodsError struct {
LogLevel int
Message string
IRODSCode string
Time time.Time
}
// Error returns error string, alias of String(). Sample output:
//
// 2016-04-22 10:02:30.802355258 -0400 EDT: Fatal - iRODS Connect Failed: rcConnect failed
func (err *GoRodsError) Error() string {
return err.String()
}
// String returns error string. Sample output:
//
// 2016-04-22 10:02:30.802355258 -0400 EDT: Fatal - iRODS Connect Failed: rcConnect failed
func (err *GoRodsError) String() string {
return fmt.Sprintf("%v: %v - %v%v", err.Time, err.lookupError(err.LogLevel), err.Message, err.IRODSCode)
}
func (err *GoRodsError) lookupError(code int) string {
var constLookup = map[int]string{
Info: "Info",
Warn: "Warn",
Fatal: "Fatal",
}
return constLookup[code]
}
func newError(logLevel int, status C.int, message string) *GoRodsError {
var (
errStr *C.char
subErrStr *C.char
)
err := new(GoRodsError)
err.LogLevel = logLevel
err.Message = message
err.Time = time.Now()
if status != -1 {
defer C.free(unsafe.Pointer(errStr))
defer C.free(unsafe.Pointer(subErrStr))
errStr = C.rodsErrorName(status, &subErrStr)
err.IRODSCode = " " + C.GoString(errStr) + " " + C.GoString(subErrStr)
}
return err
}