lslError function
Builds an LSLException for a nonzero liblsl error code, naming the code and appending liblsl's own message for it when one is available.
Must be called on the thread that made the failing call: liblsl keeps the message in a thread-local buffer, so calling this from a different isolate than the one that failed yields the code alone.
Implementation
LSLException lslError(String what, int code) {
final name = switch (code) {
-1 => 'timeout',
-2 => 'lost',
-3 => 'argument',
-4 => 'internal',
_ => 'unknown',
};
final detailPtr = lsl_last_error();
final detail = detailPtr.isNullPointer
? ''
: detailPtr.cast<Utf8>().toDartString();
final suffix = detail.isEmpty ? '' : ': $detail';
return code == -1
? LSLTimeout('$what: $name error ($code)$suffix')
: LSLException('$what: $name error ($code)$suffix');
}