1package forestdb
2
3//  Copyright (c) 2014 Couchbase, Inc.
4//  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5//  except in compliance with the License. You may obtain a copy of the License at
6//    http://www.apache.org/licenses/LICENSE-2.0
7//  Unless required by applicable law or agreed to in writing, software distributed under the
8//  License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
9//  either express or implied. See the License for the specific language governing permissions
10//  and limitations under the License.
11
12//#include <libforestdb/forestdb.h>
13import "C"
14import "fmt"
15
16const (
17	RESULT_SUCCESS                  C.fdb_status = 0
18	RESULT_INVALID_ARGS             Error        = -1
19	RESULT_OPEN_FAIL                Error        = -2
20	RESULT_NO_SUCH_FILE             Error        = -3
21	RESULT_WRITE_FAIL               Error        = -4
22	RESULT_READ_FAIL                Error        = -5
23	RESULT_CLOSE_FAIL               Error        = -6
24	RESULT_COMMIT_FAIL              Error        = -7
25	RESULT_ALLOC_FAIL               Error        = -8
26	RESULT_KEY_NOT_FOUND            Error        = -9
27	RESULT_RONLY_VIOLATION          Error        = -10
28	RESULT_COMPACTION_FAIL          Error        = -11
29	RESULT_ITERATOR_FAIL            Error        = -12
30	RESULT_SEEK_FAIL                Error        = -13
31	RESULT_FSYNC_FAIL               Error        = -14
32	RESULT_CHECKSUM_ERROR           Error        = -15
33	RESULT_FILE_CORRUPTION          Error        = -16
34	RESULT_COMPRESSION_FAIL         Error        = -17
35	RESULT_NO_DB_INSTANCE           Error        = -18
36	RESULT_FAIL_BY_ROLLBACK         Error        = -19
37	RESULT_INVALID_CONFIG           Error        = -20
38	RESULT_MANUAL_COMPACTION_FAIL   Error        = -21
39	RESULT_INVALID_COMPACTION_MODE  Error        = -22
40	RESULT_FILE_IS_BUSY             Error        = -23
41	RESULT_FILE_REMOVE_FAIL         Error        = -24
42	RESULT_FILE_RENAME_FAIL         Error        = -25
43	RESULT_TRANSACTION_FAIL         Error        = -26
44	RESULT_FAIL_BY_TRANSACTION      Error        = -27
45	RESULT_FAIL_BY_COMPACTION       Error        = -28
46	RESULT_TOO_LONG_FILENAME        Error        = -29
47	RESULT_INVALID_HANDLE           Error        = -30
48	RESULT_KV_STORE_NOT_FOUND       Error        = -31
49	RESULT_KV_STORE_BUSY            Error        = -32
50	RESULT_INVALID_KV_INSTANCE_NAME Error        = -33
51	RESULT_INVALID_CMP_FUNCTION     Error        = -34
52	RESULT_IN_USE_BY_COMPACTOR      Error        = -35
53	RESULT_FILE_NOT_OPEN            Error        = -36
54	RESULT_TOO_BIG_BUFFER_CACHE     Error        = -37
55	RESULT_NO_DB_HEADERS            Error        = -38
56	RESULT_HANDLE_BUSY              Error        = -39
57	RESULT_AIO_NOT_SUPPORTED        Error        = -40
58	RESULT_AIO_INIT_FAIL            Error        = -41
59	RESULT_AIO_SUBMIT_FAIL          Error        = -42
60	RESULT_AIO_GETEVENTS_FAIL       Error        = -43
61	RESULT_CRYPTO_ERROR             Error        = -44
62	RESULT_FAIL                     Error        = -100
63)
64
65type Error int
66
67func (e Error) Error() string {
68	if msg, ok := resultMessages[int(e)]; ok {
69		return msg
70	}
71	return fmt.Sprintf("unknown forestdb error: %d", e)
72}
73
74var resultMessages = map[int]string{
75	0:    "success",
76	-1:   "invalid args",
77	-2:   "open fail",
78	-3:   "no such file",
79	-4:   "write fail",
80	-5:   "read fail",
81	-6:   "close fail",
82	-7:   "commit fail",
83	-8:   "alloc fail",
84	-9:   "key not found",
85	-10:  "read-only violation",
86	-11:  "compaction fail",
87	-12:  "iterator fail",
88	-13:  "seek fail",
89	-14:  "fsync fail",
90	-15:  "checksum error",
91	-16:  "file corruption",
92	-17:  "compression fail",
93	-18:  "no db instance",
94	-19:  "fail by rollback",
95	-20:  "invalid config",
96	-21:  "manual compaction fail",
97	-22:  "invalid compaction mode",
98	-23:  "file is busy",
99	-24:  "file remove fail",
100	-25:  "file rename fail",
101	-26:  "transaction fail",
102	-27:  "failed due to active transactions",
103	-28:  "failed due to an active compaction task",
104	-29:  "filename is too long",
105	-30:  "forestdb handle is invalid",
106	-31:  "kv store not found in database",
107	-32:  "there is an opened handle of the kv store",
108	-33:  "same kv instance name already exists",
109	-34:  "custom compare function is assigned incorrectly",
110	-35:  "db file can't be destroyed as the file is being compacted",
111	-36:  "db file used in this operation has not been opened",
112	-37:  "buffer cache too big",
113	-38:  "no commit headers in a database file",
114	-39:  "db handle is being used by another thread",
115	-40:  "asynchronous io is not supported in the current os version",
116	-41:  "asynchronous io init fails",
117	-42:  "asynchronous io submit fails",
118	-43:  "fail to read asynchronous io events from the completion queue",
119	-44:  "error encrypting or decrypting data, or unsupported encryption algorithm",
120	-100: "fail",
121}
122