-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy patherror.go
67 lines (55 loc) · 1.02 KB
/
error.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
package onnxruntime
// #include "cbits/predictor.hpp"
// #include <stdlib.h>
import "C"
import (
"unsafe"
"github.com/pkg/errors"
)
/* Description: The interface for getting errors thrown by C++.
* Referenced: https://github.com/c3sr/go-pytorch/blob/master/errors.go
*/
// Error returned by C++
type Error struct {
message string
}
func (e *Error) Error() string {
return e.message
}
func checkError(err C.ORT_Error) *Error {
if err.message != nil {
defer C.free(unsafe.Pointer(err.message))
return &Error{
message: C.GoString(err.message),
}
}
return nil
}
func HasError() bool {
return int(C.ORT_HasError()) == 1
}
func GetErrorString() string {
msg := C.ORT_GetErrorString()
if msg == nil {
return ""
}
return C.GoString(msg)
}
func ResetError() {
C.ORT_ResetError()
}
func GetError() error {
if !HasError() {
return nil
}
err := errors.New(GetErrorString())
ResetError()
return err
}
func PanicOnError() {
msg := C.ORT_GetErrorString()
if msg == nil {
return
}
panic(C.GoString(msg))
}