@@ -132,8 +132,8 @@ cdef inline object c_err_code_to_py(line_sender_error_code code):
132
132
raise ValueError (' Internal error converting error code.' )
133
133
134
134
135
- cdef inline object c_err_to_py (line_sender_error* err):
136
- """ Construct a ``SenderError`` from a C error, which will also be freed."""
135
+ cdef inline object c_err_to_code_and_msg (line_sender_error* err):
136
+ """ Construct a ``SenderError`` from a C error, which will be freed."""
137
137
cdef line_sender_error_code code = line_sender_error_get_code(err)
138
138
cdef size_t c_len = 0
139
139
cdef const char * c_msg = line_sender_error_msg(err, & c_len)
@@ -142,15 +142,24 @@ cdef inline object c_err_to_py(line_sender_error* err):
142
142
cdef object py_code
143
143
try :
144
144
py_code = c_err_code_to_py(code)
145
- py_msg = PyUnicode_FromKindAndData(
146
- PyUnicode_1BYTE_KIND,
147
- c_msg,
148
- < Py_ssize_t> c_len)
149
- return IngressError(py_code, py_msg)
145
+ py_msg = PyUnicode_FromStringAndSize(c_msg, < Py_ssize_t> c_len)
146
+ return (py_code, py_msg)
150
147
finally :
151
148
line_sender_error_free(err)
152
149
153
150
151
+ cdef inline object c_err_to_py(line_sender_error* err):
152
+ """ Construct an ``IngressError`` from a C error, which will be freed."""
153
+ cdef object tup = c_err_to_code_and_msg(err)
154
+ return IngressError(tup[0 ], tup[1 ])
155
+
156
+
157
+ cdef inline object c_err_to_py_fmt(line_sender_error* err, str fmt):
158
+ """ Construct an ``IngressError`` from a C error, which will be freed."""
159
+ cdef object tup = c_err_to_code_and_msg(err)
160
+ return IngressError(tup[0 ], fmt.format(tup[1 ]))
161
+
162
+
154
163
cdef bytes str_to_utf8(str string, line_sender_utf8* utf8_out):
155
164
"""
156
165
Init the `utf8_out` object from the `string`.
@@ -932,6 +941,11 @@ cdef class Buffer:
932
941
# raise ValueError('nyi')
933
942
934
943
944
+ _FLUSH_FMT = (' {} - See https://py-questdb-client.readthedocs.io/en/'
945
+ ' v1.0.1'
946
+ ' /troubleshooting.html#inspecting-and-debugging-errors#flush-failed' )
947
+
948
+
935
949
cdef class Sender:
936
950
"""
937
951
A sender is a client that inserts rows into QuestDB via the ILP protocol.
@@ -1313,10 +1327,10 @@ cdef class Sender:
1313
1327
try :
1314
1328
if clear:
1315
1329
if not line_sender_flush(self ._impl, c_buf, & err):
1316
- raise c_err_to_py (err)
1330
+ raise c_err_to_py_fmt (err, _FLUSH_FMT )
1317
1331
else :
1318
1332
if not line_sender_flush_and_keep(self ._impl, c_buf, & err):
1319
- raise c_err_to_py (err)
1333
+ raise c_err_to_py_fmt (err, _FLUSH_FMT )
1320
1334
except :
1321
1335
# Prevent a follow-up call to `.close(flush=True)` (as is usually
1322
1336
# called from `__exit__`) to raise after the sender entered an error
0 commit comments