Skip to content

Commit 831fa24

Browse files
committed
Improve errors returned by gotox.New()
1 parent a36c5fd commit 831fa24

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

PROGRESS.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# List of implemented toxcore features
2-
`DONE` This means the function is already implemented.
3-
`WONT` This means the function will probably not be implemented.
2+
`DONE` means the function is already implemented.
3+
`WONT` means the function will probably not be implemented.
44

55
Groupchats will probably not be added before the new groupchat API is ready.
66

bindings.go

+26-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,32 @@ func New(options *Options) (*Tox, error) {
8585
cTox = C.tox_new(cOptions, &toxErrNew)
8686
if cTox == nil || ToxErrNew(toxErrNew) != TOX_ERR_NEW_OK {
8787
C.tox_options_free(cOptions)
88-
return nil, ErrToxNew
88+
switch ToxErrNew(toxErrNew) {
89+
case TOX_ERR_NEW_NULL:
90+
return nil, ErrArgs
91+
case TOX_ERR_NEW_MALLOC:
92+
return nil, ErrNewMalloc
93+
case TOX_ERR_NEW_PORT_ALLOC:
94+
return nil, ErrNewPortAlloc
95+
case TOX_ERR_NEW_PROXY_BAD_TYPE:
96+
return nil, ErrNewProxy
97+
case TOX_ERR_NEW_PROXY_BAD_HOST:
98+
return nil, ErrNewProxy
99+
case TOX_ERR_NEW_PROXY_BAD_PORT:
100+
return nil, ErrNewProxy
101+
case TOX_ERR_NEW_PROXY_NOT_FOUND:
102+
return nil, ErrNewProxy
103+
case TOX_ERR_NEW_LOAD_ENCRYPTED:
104+
return nil, ErrNewLoadEnc
105+
case TOX_ERR_NEW_LOAD_BAD_FORMAT:
106+
return nil, ErrNewLoadBadFormat
107+
}
108+
109+
if cTox == nil {
110+
return nil, ErrToxNew
111+
}
112+
113+
return nil, ErrUnknown
89114
}
90115

91116
t := &Tox{tox: cTox, cOptions: cOptions}

const.go

+8
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ var (
8989
ErrUnknown = errors.New("An unknown error occoured")
9090
)
9191

92+
var (
93+
ErrNewMalloc = errors.New("Memory allocation failed")
94+
ErrNewPortAlloc = errors.New("Could not bind to port")
95+
ErrNewProxy = errors.New("Invalid proxy configuration")
96+
ErrNewLoadEnc = errors.New("The savedata is encrypted")
97+
ErrNewLoadBadFormat = errors.New("The savedata format is invalid")
98+
)
99+
92100
type ToxErrNew C.enum_TOX_ERR_NEW
93101

94102
const (

0 commit comments

Comments
 (0)