Hi Ben,

The actual protocol framing on error is:

{partial result} \00 \01 {error message} \00

Both bytes are present: all results end with a single \00 byte, which indicates that the process was successful. If an error occurs, an additional byte \01 is sent, which is then followed by the error message string.

The worked example in the docs makes this concrete [1]: For the query 1, 2+'3', the server sends the partial result "1" terminated with \00, then \01 followed by the error text “Stopped at...”, and finally a closing \00 that terminates the error string itself.

The success terminator \00 is always sent; \01 is an additional indicator after it, followed by a \00-terminated error message.

What this means for your implementation:

• Read until \00: that's the (possibly partial) result.
• Don't treat \01 as the end marker; it appears after the \00.
• Peek the next byte. If it's \00, success. If it’s \01, read until the next \00 to get the error message.

In your current code, treating “ends with \01” as the error signal will work for detection only if you’re reading the whole stream as one blob, but you’ll lose the error message itself and misframe the result boundary. The fix is to consume the error string after the \01.

Cheers 
Christian

[1] https://docs.basex.org/main/Server_Protocol#example


Von: Ben Engbers via BaseX-Talk <basex-talk@mailman.uni-konstanz.de>
Gesendet: Mittwoch, April 29, 2026 12:45:42 AM
An: Basex Mail-lijst <basex-talk@mailman.uni-konstanz.de>
Betreff: [basex-talk] Error handling according to the server protocol

Hi,
I am currently busy writing C wrapper functions around the public
functions from my libBasexCpp library (see
https://github.com/BenEngbers/libBasexCpp). In doing so, I discovered an
imperfection in that library and an ambiguity in the server protocol.
The description of the command protocol states that in the event of an
error, the server response consists of {partial result} {error} \01.
However, at the bottom of the description of the Query protocol, it is
stated that the server response ends with a \01, followed by an error
string.
In the current implementation, I assumed that all successfully executed
requests end with a \00 and that a \01 at the end means an error has
occurred.
My question is whether this assumption is correct or whether I need to
adjust my implementation so that the \01 is followed by the error message?

Ben