xref: /6.0.3/forestdb/src/fdb_errors.cc (revision 56236603)
1/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 *     Copyright 2014 Couchbase, Inc
4 *
5 *   Licensed under the Apache License, Version 2.0 (the "License");
6 *   you may not use this file except in compliance with the License.
7 *   You may obtain a copy of the License at
8 *
9 *       http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *   Unless required by applicable law or agreed to in writing, software
12 *   distributed under the License is distributed on an "AS IS" BASIS,
13 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *   See the License for the specific language governing permissions and
15 *   limitations under the License.
16 */
17
18#include <stdlib.h>
19
20#include "libforestdb/forestdb.h"
21#include "fdb_internal.h"
22
23LIBFDB_API
24const char* fdb_error_msg(fdb_status err_code)
25{
26    switch (err_code)
27    {
28        case FDB_RESULT_SUCCESS:
29            return "success";
30
31        case FDB_RESULT_INVALID_ARGS:
32            return "invalid arguments";
33
34        case FDB_RESULT_OPEN_FAIL:
35            return "error opening file";
36
37        case FDB_RESULT_NO_SUCH_FILE:
38            return "no such file";
39
40        case FDB_RESULT_WRITE_FAIL:
41            return "error writing to file";
42
43        case FDB_RESULT_READ_FAIL:
44            return "error reading from file";
45
46        case FDB_RESULT_CLOSE_FAIL:
47            return "error closing a file";
48
49        case FDB_RESULT_COMMIT_FAIL:
50            return "commit operation failed";
51
52        case FDB_RESULT_ALLOC_FAIL:
53            return "failed to allocate memory";
54
55        case FDB_RESULT_KEY_NOT_FOUND:
56            return "key not found";
57
58        case FDB_RESULT_RONLY_VIOLATION:
59            return "database is read-only";
60
61        case FDB_RESULT_COMPACTION_FAIL:
62            return "compaction operation failed";
63
64        case FDB_RESULT_ITERATOR_FAIL:
65            return "iterator operation failed";
66
67        case FDB_RESULT_SEEK_FAIL:
68            return "seek failure";
69
70        case FDB_RESULT_FSYNC_FAIL:
71            return "fsync failure";
72
73        case FDB_RESULT_CHECKSUM_ERROR:
74            return "checksum error";
75
76        case FDB_RESULT_FILE_CORRUPTION:
77            return "data corruption in file";
78
79        case FDB_RESULT_COMPRESSION_FAIL:
80            return "document compression failure";
81
82        case FDB_RESULT_NO_DB_INSTANCE:
83            return "database instance not found";
84
85        case FDB_RESULT_FAIL_BY_ROLLBACK:
86            return "operation failed due to rollback";
87
88        case FDB_RESULT_INVALID_CONFIG:
89            return "invalid configuration";
90
91        case FDB_RESULT_MANUAL_COMPACTION_FAIL:
92            return "manual compaction failed";
93
94        case FDB_RESULT_INVALID_COMPACTION_MODE:
95            return "invalid compaction mode";
96
97        case FDB_RESULT_FILE_IS_BUSY:
98            return "file handle is busy";
99
100        case FDB_RESULT_FILE_REMOVE_FAIL:
101            return "file removal operation failed";
102
103        case FDB_RESULT_FILE_RENAME_FAIL:
104            return "file rename operation failed";
105
106        case FDB_RESULT_TRANSACTION_FAIL:
107            return "transaction operation failed";
108
109        case FDB_RESULT_FAIL_BY_TRANSACTION:
110            return "operation failed due to active transaction";
111
112        case FDB_RESULT_FAIL_BY_COMPACTION:
113            return "operation failed due to active compaction";
114
115        case FDB_RESULT_TOO_LONG_FILENAME:
116            return "filename is too long";
117
118        case FDB_RESULT_INVALID_HANDLE:
119            return "ForestDB handle is invalid";
120
121        case FDB_RESULT_KV_STORE_NOT_FOUND:
122            return "KV store not found in database";
123
124        case FDB_RESULT_KV_STORE_BUSY:
125            return "there is an active open handle on the kvstore";
126
127        case FDB_RESULT_INVALID_KV_INSTANCE_NAME:
128            return "same KV instance name already exists";
129
130        case FDB_RESULT_INVALID_CMP_FUNCTION:
131            return "custom compare function is assigned incorrectly";
132
133        case FDB_RESULT_IN_USE_BY_COMPACTOR:
134            return "file is in use by compactor, retry later";
135
136        case FDB_RESULT_FILE_NOT_OPEN:
137            return "this operations needs an opened file handle";
138
139        case FDB_RESULT_TOO_BIG_BUFFER_CACHE:
140            return "Buffer cache is too large to be configured and cannot "
141                   "exceed 80% of physical memory";
142
143        case FDB_RESULT_NO_DB_HEADERS:
144            return "No commit headers found in a database file";
145
146        case FDB_RESULT_HANDLE_BUSY:
147            return "Forestdb Handle is being used by another thread";
148
149        case FDB_RESULT_AIO_NOT_SUPPORTED:
150            return "Asynchronous I/O is not supported in the current OS";
151
152        case FDB_RESULT_AIO_INIT_FAIL:
153            return "Asynchronous I/O init fails";
154
155        case FDB_RESULT_AIO_SUBMIT_FAIL:
156            return "Asynchronous I/O init fails";
157
158        case FDB_RESULT_AIO_GETEVENTS_FAIL:
159            return "Fail to read asynchronous I/O events from the completion queue";
160
161        case FDB_RESULT_CRYPTO_ERROR:
162            return "Encryption error";
163
164        case FDB_RESULT_COMPACTION_CANCELLATION:
165            return "Compaction canceled";
166
167        case FDB_RESULT_SB_INIT_FAIL:
168            return "Superblock initialization failed";
169
170        case FDB_RESULT_SB_RACE_CONDITION:
171            return "DB file is modified during superblock initialization";
172
173        case FDB_RESULT_SB_READ_FAIL:
174            return "Superblock is corrupted";
175
176        case FDB_RESULT_FILE_VERSION_NOT_SUPPORTED:
177            return "This version of DB file is not supported";
178
179        case FDB_RECOVERABLE_ERR:
180            return "A recoverable error encountered";
181
182        case FDB_NONRECOVERABLE_ERR:
183            return "Non-recoverable error encountered";
184
185
186        // All the error codes below correspond to errno values in Linux, OSX,
187        // and Windows, which can happen in file opeations.
188
189        case FDB_RESULT_EPERM:
190            return "A file operation is not permitted";
191        case FDB_RESULT_EIO:
192            return "A physical I/O error has occurred";
193        case FDB_RESULT_ENXIO:
194            return "No such device or address error";
195        case FDB_RESULT_EBADF:
196            return "Not a valid file descriptor";
197        case FDB_RESULT_ENOMEM:
198            return "Insufficient memory was available";
199        case FDB_RESULT_EACCESS:
200            return "File access permission was denied";
201        case FDB_RESULT_EFAULT:
202            return "Outside the process's accessible address space";
203        case FDB_RESULT_EEXIST:
204            return "A file name already exists in the file system";
205        case FDB_RESULT_ENODEV:
206            return "No corresponding device exists";
207        case FDB_RESULT_ENOTDIR:
208            return "A directory component in a file path name is not a directory";
209        case FDB_RESULT_EISDIR:
210            return "A file path name refers to a directory";
211        case FDB_RESULT_EINVAL:
212            return "Arguments to a file operation are not valid";
213        case FDB_RESULT_ENFILE:
214            return "The system-wide limit on the total number of open files has "
215                   "been reached";
216        case FDB_RESULT_EMFILE:
217            return "The per-process limit on the number of open file descriptors "
218                   "has been reached";
219        case FDB_RESULT_EFBIG:
220            return "A file is too large to be opened";
221        case FDB_RESULT_ENOSPC:
222            return "No space left on device";
223        case FDB_RESULT_EROFS:
224            return "A file on a read-only filesystem and write access was requested";
225        case FDB_RESULT_EOPNOTSUPP:
226            return "A file operation is not supported";
227        case FDB_RESULT_ENOBUFS:
228            return "Insufficient buffer space was available in the system to perform "
229                   "a operation";
230        case FDB_RESULT_ELOOP:
231            return "Too many symbolic links were encountered in resolving a file path name";
232        case FDB_RESULT_ENAMETOOLONG:
233            return "A file path name was too long";
234        case FDB_RESULT_EOVERFLOW:
235            return "A file is too large to be opened";
236        case FDB_RESULT_EAGAIN:
237            return "Resource temporarily unavailable";
238
239        default:
240            return "unknown error";
241    }
242}
243