forked from SAP/cgo-ase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
43 lines (39 loc) · 1.23 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
// SPDX-FileCopyrightText: 2020 SAP SE
// SPDX-FileCopyrightText: 2021 SAP SE
// SPDX-FileCopyrightText: 2022 SAP SE
// SPDX-FileCopyrightText: 2023 SAP SE
//
// SPDX-License-Identifier: Apache-2.0
package ase
//#include "ctlib.h"
import "C"
import (
"fmt"
"strconv"
)
// makeError creates an error out of the return code of an ASE routine
// and a message.
//
// The passed message leads the error and can thus be used to add
// specific information before the generic ASE error message.
//
// The return code is turned into a message according to the Client
// Library Programmers Guide.
func makeError(retcode C.CS_RETCODE, message string, args ...interface{}) error {
// TODO parse retcode as integer and provide a map mapping error
// codes to strings to consumers in addition to MakeError.
var s string
switch retcode {
case C.CS_FAIL:
s = "Routine failed"
case C.CS_CANCELED:
s = "Routine was canceled"
case C.CS_PENDING:
s = "Operation is pending, see asynchronous programming"
case C.CS_BUSY:
s = "An operation is already pending for this connection, see asynchronous programming"
default:
s = "Unknown error code: " + strconv.FormatInt(int64(retcode), 10)
}
return fmt.Errorf("%s: %s", fmt.Sprintf(message, args...), s)
}