Skip to content

Errors ​

Python ​

xqdb defines three exception classes. All three derive directly from Exception and are not subclasses of each other. In particular, except xqdb.XqdbError does not catch an I/O or authentication failure.

ExceptionRaised for
xqdb.XqdbIOErrorConnection refused or reset, name resolution failures, socket timeouts, TLS handshake and certificate failures, and calls that need an open socket when there is none (Not Connected.). Also raised by read_binary6 for a missing file.
xqdb.XqdbAuthErrorThe server closed the connection during the handshake, which is how q rejects credentials. The message is Wrong credential.
xqdb.XqdbErrorq errors (Internal Server Error - "<q error>"), values xqdb cannot decode or encode, text that is not valid UTF-8 under symbol_encoding="strict", invalid XqdbQOperator or XqdbQLambda arguments, and files that are not tables

Standard Python exceptions cover argument problems:

ExceptionRaised for
ValueErrorAn unknown backend or symbol_encoding, a temporal atom with digits below a microsecond, a time argument that is not whole milliseconds, an unknown msg_type, values nested more than 64 levels deep, and cyclic containers
TypeErrorMore than eight query arguments, lazy frames, unsupported Python types, dictionary keys that are not str, and a non-int timeout
OverflowErrorIntegers outside the signed 64-bit range, temporal values outside the q or Python range, and a port above 65535
ModuleNotFoundErrorA backend whose package is not installed
RuntimeErrorAlready borrowed, when a second thread calls a Q that another thread is using

Catch the xqdb classes together, or one at a time from most to least specific:

python
import xqdb

conn = xqdb.Q("localhost", 1800, timeout=10)
try:
    result = conn.sync("select from trade")
except xqdb.XqdbAuthError:
    raise SystemExit("check the q username and password")
except xqdb.XqdbIOError as error:
    print(f"connection problem, safe to reconnect: {error}")
except xqdb.XqdbError as error:
    print(f"q or conversion error: {error}")

Node.js ​

Every error from a call is an XqdbError or one of its subclasses. Each has three properties:

  • code: a stable string, listed below.
  • nativeMessage: the original message from the native layer.
  • cause: the native payload, or the exception that was caught.
ClasscodeRaised for
XqdbIOErrorXQDB_IOConnection, socket, timeout, and TLS failures, calls without an open socket, and file read errors
XqdbIOErrorXQDB_NATIVE_LOADThe native addon could not be loaded. The message explains how to fix it.
XqdbAuthErrorXQDB_AUTHThe server rejected the credentials
XqdbErrorXQDB_SERVERq returned an error, such as 'type
XqdbErrorXQDB_CONVERSIONA value could not be converted in either direction. Examples are invalid UTF-8 under the strict policy, more than eight arguments, oversized or too deeply nested arguments, unsupported JavaScript values, invalid operators or lambdas, and UNC paths passed to readBinary6.
XqdbErrorXQDB_UNSUPPORTEDq types or forms that 0.1.8 cannot decode, such as month lists, negative time atoms, and big-endian messages
XqdbErrorXQDB_ERROROther errors from the core, such as Not a table
XqdbErrorXQDB_INTERNALThe connection's worker thread stopped or panicked
XqdbErrorXQDB_BACKPRESSUREThe connection already had eight commands waiting. See Node.js Workers and Backpressure.

Invalid options, such as a timeout of 0, a port outside 1 to 65535, a negative retries, or an unknown symbolEncoding, throw a RangeError synchronously from new Q() or Q.connect(). readBinary6() rejects with a RangeError for an unknown symbolEncoding.

XqdbIOError and XqdbAuthError extend XqdbError, so check them first:

ts
import { Q, XqdbAuthError, XqdbError, XqdbIOError } from "@xbbg/xqdb";

const q = new Q({ host: "localhost", port: 1800 });
try {
  console.log(await q.sync("select from trade"));
} catch (error) {
  if (error instanceof XqdbAuthError) {
    console.error("check the q username and password");
  } else if (error instanceof XqdbIOError) {
    console.error(`connection problem (${error.code}): ${error.nativeMessage}`);
  } else if (error instanceof XqdbError) {
    console.error(`${error.code}: ${error.nativeMessage}`);
  } else {
    throw error;
  }
} finally {
  await q.disconnect();
}

xbbg is independent open-source software and is not affiliated with, endorsed by, sponsored by, or approved by Bloomberg Finance L.P.