forked from chrischdi/gphoto2go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
errors.go
88 lines (76 loc) · 2.35 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
package gphoto2go
// #cgo pkg-config: libgphoto2
// #include <gphoto2.h>
import "C"
import "fmt"
const (
Err = C.GP_ERROR
ErrBadParameters = C.GP_ERROR_BAD_PARAMETERS
ErrNoMemory = C.GP_ERROR_NO_MEMORY
ErrLibrary = C.GP_ERROR_LIBRARY
ErrUnknownPort = C.GP_ERROR_UNKNOWN_PORT
ErrNotSupported = C.GP_ERROR_NOT_SUPPORTED
ErrIO = C.GP_ERROR_IO
ErrFixedLimitExceeded = C.GP_ERROR_FIXED_LIMIT_EXCEEDED
ErrTimeout = C.GP_ERROR_TIMEOUT
ErrIOSupportedSerial = C.GP_ERROR_IO_SUPPORTED_SERIAL
ErrIOSupportedUSB = C.GP_ERROR_IO_SUPPORTED_USB
ErrIOInit = C.GP_ERROR_IO_INIT
ErrIORead = C.GP_ERROR_IO_READ
ErrIOWrite = C.GP_ERROR_IO_WRITE
ErrIOUpdate = C.GP_ERROR_IO_UPDATE
ErrIOSerialSpeed = C.GP_ERROR_IO_SERIAL_SPEED
ErrIOUSBClearHalt = C.GP_ERROR_IO_USB_CLEAR_HALT
ErrIOUSBFind = C.GP_ERROR_IO_USB_FIND
ErrIOUSBClaim = C.GP_ERROR_IO_USB_CLAIM
ErrIOLock = C.GP_ERROR_IO_LOCK
ErrHal = C.GP_ERROR_HAL
ErrCorruptedData = C.GP_ERROR_CORRUPTED_DATA
ErrFileExists = C.GP_ERROR_FILE_EXISTS
ErrModelNotFound = C.GP_ERROR_MODEL_NOT_FOUND
ErrDirectoryNotFound = C.GP_ERROR_DIRECTORY_NOT_FOUND
ErrFileNotFound = C.GP_ERROR_FILE_NOT_FOUND
ErrDirectoryExists = C.GP_ERROR_DIRECTORY_EXISTS
ErrCameraBusy = C.GP_ERROR_CAMERA_BUSY
ErrPathNotAbsolute = C.GP_ERROR_PATH_NOT_ABSOLUTE
ErrCancel = C.GP_ERROR_CANCEL
ErrCameraError = C.GP_ERROR_CAMERA_ERROR
ErrOsFailure = C.GP_ERROR_OS_FAILURE
ErrNoSpace = C.GP_ERROR_NO_SPACE
)
const (
errUnknown = "libgphoto2: unknown error"
)
type Error struct {
code int
message string
}
func (e *Error) Error() string {
return fmt.Sprintf("libgphoto2: [%d] %s", e.code, e.message)
}
func (e *Error) Code() int {
return e.code
}
func (e *Error) Message() string {
return e.message
}
func (e *Error) Is(i int) bool {
return e.code == i
}
func cameraResultToError(code C.int) error {
if code == 0 {
return nil
}
str := C.GoString(C.gp_result_as_string(code))
if str == "" {
str = errUnknown
}
return &Error{
code: int(code),
message: str,
}
}
// CameraResultToString func
func CameraResultToString(err C.int) string {
return C.GoString(C.gp_result_as_string(err))
}