-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.cpp
88 lines (84 loc) · 2.83 KB
/
errors.cpp
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
#include "errors.h"
#include "lmdb.h"
void OocError::pythonize() const {
switch(errorCode) {
case NoError:
PyErr_Format(PyExc_ValueError, "Error: There is no error.");
break;
case AlreadyPythonizedError:
break;
case ImmutableValueNotFound:
PyErr_Format(PyExc_ValueError, "Tried to write a non-existant immutable value into the DB in a readonly transaction.");
break;
case InvalidBool:
PyErr_Format(PyExc_ValueError, "Found a bool that's neither true nor false.");
break;
case CouldNotReadyString:
PyErr_Format(PyExc_MemoryError, "Could not bring string into the canonical representation.");
break;
case InvalidStringKind:
PyErr_Format(PyExc_ValueError, "Unknown kind of string");
break;
case OutOfMemory:
PyErr_NoMemory();
break;
case UnknownType:
PyErr_Format(PyExc_ValueError, "Tried to serialize or deserialize object of unknown type");
break;
case UnknownHardcodedValue:
PyErr_Format(PyExc_AssertionError, "Unexpected hardcoded value");
break;
case UnexpectedData:
PyErr_Format(PyExc_AssertionError, "Unexpected data in database");
break;
case IndexError:
PyErr_Format(PyExc_IndexError, "index out of range");
break;
case MdbError:
PyErr_Format(PyExc_IOError, "Unknown problem with LMDB");
break;
case MutableValueNotAllowed:
PyErr_Format(PyExc_ValueError, "Mutable values are not allowed here");
break;
case WriteNotAllowed:
PyErr_Format(PyExc_ValueError, "Not allowed to write now");
break;
}
}
void UnknownTypeError::pythonize() const {
PyErr_Format(
PyExc_ValueError,
"Cannot serialize objects of type %s",
PyUnicode_AsUTF8(PyObject_Repr(type)));
}
void MdbError::pythonize() const {
switch(mdbErrorCode) {
case 0:
PyErr_Format(PyExc_ValueError, "Error: There is no error.");
break;
case ENOMEM:
PyErr_NoMemory();
break;
case EINVAL:
PyErr_Format(PyExc_IOError,"LMDB: An invalid parameter was specified.");
break;
case ENOSPC:
PyErr_Format(PyExc_IOError,"LMDB: No more disk space.");
break;
case EIO:
PyErr_Format(PyExc_IOError,"LMDB: A low-level I/O error occurred while writing.");
break;
case EACCES:
PyErr_Format(PyExc_IOError, "LMDB: Access denied");
break;
case ENOENT:
PyErr_Format(PyExc_IOError, "LMDB Error: The directory specified by the path parameter doesn't exist.");
break;
case EAGAIN:
PyErr_Format(PyExc_IOError, "LMDB Error: The environment was locked by another process.");
break;
default:
PyErr_Format(PyExc_IOError, "MDB Error: %s", mdb_strerror(mdbErrorCode));
break;
}
}