@@ -132,8 +132,8 @@ cdef inline object c_err_code_to_py(line_sender_error_code code):
132132 raise ValueError (' Internal error converting error code.' )
133133
134134
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."""
137137 cdef line_sender_error_code code = line_sender_error_get_code(err)
138138 cdef size_t c_len = 0
139139 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):
142142 cdef object py_code
143143 try :
144144 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)
150147 finally :
151148 line_sender_error_free(err)
152149
153150
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+
154163cdef bytes str_to_utf8(str string, line_sender_utf8* utf8_out):
155164 """
156165 Init the `utf8_out` object from the `string`.
@@ -932,6 +941,11 @@ cdef class Buffer:
932941 # raise ValueError('nyi')
933942
934943
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+
935949cdef class Sender:
936950 """
937951 A sender is a client that inserts rows into QuestDB via the ILP protocol.
@@ -1313,10 +1327,10 @@ cdef class Sender:
13131327 try :
13141328 if clear:
13151329 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 )
13171331 else :
13181332 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 )
13201334 except :
13211335 # Prevent a follow-up call to `.close(flush=True)` (as is usually
13221336 # called from `__exit__`) to raise after the sender entered an error
0 commit comments