brlapi_error(3)
β¨ NAME β¨
brlapi_error β Error handling, bestie π
- How to handle errors.
ok so this is the <pink>brlapi_error(3)</pink> page from the Library Functions Manual. it's a long one so we're splitting it β this is part 1, stay with me π«Ά
πΈ SYNOPSIS πΈ
π Data Structures
struct brlapi_error_t
π Macros
#define brlapi_error (*brlapi_error_location())
#define brlapi_errno (brlapi_error.brlerrno)
#define brlapi_libcerrno (brlapi_error.libcerrno)
#define brlapi_gaierrno (brlapi_error.gaierrno)
#define brlapi_errfun (brlapi_error.errfun)
π Typedefs
typedef uint32_t brlapi_packetType_t
typedef void(BRLAPI_STDCALL * brlapi_exceptionHandler_t) (int error,
brlapi_packetType_t type, const void *packet, size_t size)
typedef void(BRLAPI_STDCALL * brlapi__exceptionHandler_t)
(brlapi_handle_t *handle, int error, brlapi_packetType_t type, const
void *packet, size_t size)
π Enumerations
enum brlapi_error { BRLAPI_ERROR_SUCCESS = 0, BRLAPI_ERROR_SUCCESS = 0,
BRLAPI_ERROR_NOMEM = 1, BRLAPI_ERROR_NOMEM = 1, BRLAPI_ERROR_TTYBUSY
= 2, BRLAPI_ERROR_TTYBUSY = 2, BRLAPI_ERROR_DEVICEBUSY = 3,
BRLAPI_ERROR_DEVICEBUSY = 3, BRLAPI_ERROR_UNKNOWN_INSTRUCTION = 4,
BRLAPI_ERROR_UNKNOWN_INSTRUCTION = 4,
BRLAPI_ERROR_ILLEGAL_INSTRUCTION = 5,
BRLAPI_ERROR_ILLEGAL_INSTRUCTION = 5, BRLAPI_ERROR_INVALID_PARAMETER
= 6, BRLAPI_ERROR_INVALID_PARAMETER = 6, BRLAPI_ERROR_INVALID_PACKET
= 7, BRLAPI_ERROR_INVALID_PACKET = 7, BRLAPI_ERROR_CONNREFUSED = 8,
BRLAPI_ERROR_CONNREFUSED = 8, BRLAPI_ERROR_OPNOTSUPP = 9,
BRLAPI_ERROR_OPNOTSUPP = 9, BRLAPI_ERROR_GAIERR = 10,
BRLAPI_ERROR_GAIERR = 10, BRLAPI_ERROR_LIBCERR = 11,
BRLAPI_ERROR_LIBCERR = 11, BRLAPI_ERROR_UNKNOWNTTY = 12,
BRLAPI_ERROR_UNKNOWNTTY = 12, BRLAPI_ERROR_PROTOCOL_VERSION = 13,
BRLAPI_ERROR_PROTOCOL_VERSION = 13, BRLAPI_ERROR_EOF = 14,
BRLAPI_ERROR_EOF = 14, BRLAPI_ERROR_EMPTYKEY = 15,
BRLAPI_ERROR_EMPTYKEY = 15, BRLAPI_ERROR_DRIVERERROR = 16,
BRLAPI_ERROR_DRIVERERROR = 16, BRLAPI_ERROR_AUTHENTICATION = 17,
BRLAPI_ERROR_AUTHENTICATION = 17, BRLAPI_ERROR_READONLY_PARAMETER =
18, BRLAPI_ERROR_READONLY_PARAMETER = 18 }
π Functions
void BRLAPI_STDCALL brlapi_perror (const char *s)
brlapi_error_t *BRLAPI_STDCALL brlapi_error_location (void)
const char *BRLAPI_STDCALL brlapi_strerror (const brlapi_error_t *error)
size_t BRLAPI_STDCALL brlapi_strerror_r (const brlapi_error_t *error,
char *buf, size_t buflen)
const char *BRLAPI_STDCALL brlapi_getPacketTypeName (brlapi_packetType_t
type)
int BRLAPI_STDCALL brlapi_strexception (char *buffer, size_t bufferSize,
int error, brlapi_packetType_t type, const void *packet, size_t
packetSize)
int BRLAPI_STDCALL brlapi__strexception (brlapi_handle_t *handle, char
*buffer, size_t bufferSize, int error, brlapi_packetType_t type,
const void *packet, size_t packetSize)
brlapi_exceptionHandler_t BRLAPI_STDCALL brlapi_setExceptionHandler
(brlapi_exceptionHandler_t handler)
brlapi__exceptionHandler_t BRLAPI_STDCALL brlapi__setExceptionHandler
(brlapi_handle_t *handle, brlapi__exceptionHandler_t handler)
void BRLAPI_STDCALL brlapi_defaultExceptionHandler (int error,
brlapi_packetType_t type, const void *packet, size_t size)
void BRLAPI_STDCALL brlapi__defaultExceptionHandler (brlapi_handle_t
*handle, int error, brlapi_packetType_t type, const void *packet,
size_t size)
π Variables
const char * brlapi_errlist []
const int brlapi_nerr
brlapi_error_t brlapi_error
enum brlapi_error brlapi_errno
int brlapi_libcerrno
int brlapi_gaierrno
const char * brlapi_errfun
π Detailed Description π
okay so here's the whole vibe: when a function fails, brlapi_errno will hold an error code that explains why it failed. and likeβ¦ you should always report it somehow, bestie. don't just swallow it, that's giving "I don't debug" energy π
although most errors get reported that way, some of them β the ones we call exceptions β get reported asynchronously, for efficiency reasons, because they always just report a programming error. the affected functions are: brlapi_setFocus, brlapi_write* and brlapi_sendRaw. when one of those happens, the next call to brlapi_something will close the connection and call the exception handler. and if the exception handler returns, the brlapi_something function will return an end-of-file error. π
the default exception handler (brlapi_defaultExceptionHandler()) dumps the guilty packet before abort()ing. yes, abort()ing, we're not playing. it can be replaced by calling brlapi_setExceptionHandler(). for instance, the Java and Python bindings use this for raising a Java or Python exception that may be caught. iconic behavior honestly πβ
π Macro Definition Documentation π
#define brlapi_errfun (brlapi_error.errfun)
Cheat about the brlapi_errfun C token.
Referenced by brlapi_error_location().
#define brlapi_errno (brlapi_error.brlerrno)
Cheat about the brlapi_errno C token.
Referenced by brlapi_error_location().
#define brlapi_error (*brlapi_error_location())
Cheat about the brlapi_error C token.
Referenced by brlapi_error_location().
#define brlapi_gaierrno (brlapi_error.gaierrno)
Cheat about the brlapi_gaierrno C token.
Referenced by brlapi_error_location().
#define brlapi_libcerrno (brlapi_error.libcerrno)
Cheat about the brlapi_libcerrno C token.
Referenced by brlapi_error_location().
π¦ Typedef Documentation π¦
typedef void(BRLAPI_STDCALL * brlapi__exceptionHandler_t) (brlapi_handle_t *handle, int error, brlapi_packetType_t type, const void *packet, size_t size)
typedef void(BRLAPI_STDCALL * brlapi_exceptionHandler_t) (int error, brlapi_packetType_t type, const void *packet, size_t size)
Types for exception handlers.
these are the types of exception handlers which are to be given to brlapi_setExceptionHandler() and brlapi__setExceptionHandler(). slay π«Ά
Parameters
- error is a
BRLAPI_ERROR_error code; - type is the type of the guilty packet;
- packet points to the content of the guilty packet (might be a little bit truncated);
- size gives the guilty packet's size.
typedef uint32_t brlapi_packetType_t
Type for packet type. only unsigned can cross networks, 32bits. no cap β¨
π Enumeration Type Documentation π
enum brlapi_error
BrlAPI Error codes π
Enumerator
heads up bestie: the original docs list every single one of these twice β so we're listing them twice too. we don't gatekeep, we don't skip, we keep every detail fr fr π
BRLAPI_ERROR_SUCCESSβ SuccessBRLAPI_ERROR_SUCCESSβ SuccessBRLAPI_ERROR_NOMEMβ Not enough memoryBRLAPI_ERROR_NOMEMβ Not enough memoryBRLAPI_ERROR_TTYBUSYβ A connection is already running in this ttyBRLAPI_ERROR_TTYBUSYβ A connection is already running in this ttyBRLAPI_ERROR_DEVICEBUSYβ A connection is already using RAW or suspend modeBRLAPI_ERROR_DEVICEBUSYβ A connection is already using RAW or suspend modeBRLAPI_ERROR_UNKNOWN_INSTRUCTIONβ Not implemented in protocolBRLAPI_ERROR_UNKNOWN_INSTRUCTIONβ Not implemented in protocolBRLAPI_ERROR_ILLEGAL_INSTRUCTIONβ Forbiden in current modeBRLAPI_ERROR_ILLEGAL_INSTRUCTIONβ Forbiden in current modeBRLAPI_ERROR_INVALID_PARAMETERβ Out of range or have no senseBRLAPI_ERROR_INVALID_PARAMETERβ Out of range or have no senseBRLAPI_ERROR_INVALID_PACKETβ Invalid sizeBRLAPI_ERROR_INVALID_PACKETβ Invalid sizeBRLAPI_ERROR_CONNREFUSEDβ Connection refusedBRLAPI_ERROR_CONNREFUSEDβ Connection refusedBRLAPI_ERROR_OPNOTSUPPβ Operation not supportedBRLAPI_ERROR_OPNOTSUPPβ Operation not supportedBRLAPI_ERROR_GAIERRβ Getaddrinfo errorBRLAPI_ERROR_GAIERRβ Getaddrinfo errorBRLAPI_ERROR_LIBCERRβ Libc errorBRLAPI_ERROR_LIBCERRβ Libc errorBRLAPI_ERROR_UNKNOWNTTYβ Couldn't find out the tty numberBRLAPI_ERROR_UNKNOWNTTYβ Couldn't find out the tty numberBRLAPI_ERROR_PROTOCOL_VERSIONβ Bad protocol versionBRLAPI_ERROR_PROTOCOL_VERSIONβ Bad protocol versionBRLAPI_ERROR_EOFβ Unexpected end of fileBRLAPI_ERROR_EOFβ Unexpected end of fileBRLAPI_ERROR_EMPTYKEYβ Key file emptyBRLAPI_ERROR_EMPTYKEYβ Key file emptyBRLAPI_ERROR_DRIVERERRORβ Packet returned by driver too largeBRLAPI_ERROR_DRIVERERRORβ Packet returned by driver too largeBRLAPI_ERROR_AUTHENTICATIONβ Authentication failedBRLAPI_ERROR_AUTHENTICATIONβ Authentication failedBRLAPI_ERROR_READONLY_PARAMETERβ Parameter can not be changedBRLAPI_ERROR_READONLY_PARAMETERβ Parameter can not be changed
π Function Documentation π
Okay bestie, this is the part where we meet the actual functions. Every single one of them. Grab a snack π
πΈ void BRLAPI_STDCALL brlapi__defaultExceptionHandler (brlapi_handle_t * handle, int error, brlapi_packetType_t type, const void * packet, size_t size)
The internal default exception handler, fr fr. It references BRLAPI_STDCALL.
πΈ brlapi__exceptionHandler_t BRLAPI_STDCALL brlapi__setExceptionHandler (brlapi_handle_t * handle, brlapi__exceptionHandler_t handler)
The internal exception handler setter, bestie. It references BRLAPI_STDCALL.
πΈ int BRLAPI_STDCALL brlapi__strexception (brlapi_handle_t * handle, char * buffer, size_t bufferSize, int error, brlapi_packetType_t type, const void * packet, size_t packetSize)
The internal version of the exception stringifier π
. It references BRLAPI_STDCALL.
πΈ void BRLAPI_STDCALL brlapi_defaultExceptionHandler (int error, brlapi_packetType_t type, const void * packet, size_t size)
The public default exception handler, periodt. It references BRLAPI_STDCALL.
πΈ brlapi_error_t *BRLAPI_STDCALL brlapi_error_location (void )
Get per-thread error location β no cap, that's literally what it does.
So here's the tea: in multithreaded software, brlapi_error is thread-specific. Which means api.h is out here cheating about the brlapi_error token and actually calls brlapi_error_location() instead. Sneaky but iconic. π
This gets the thread specific location of global variable brlapi_error.
It references brlapi_errfun, brlapi_errno, brlapi_error, brlapi_gaierrno, brlapi_libcerrno, and BRLAPI_STDCALL.
πΈ const char *BRLAPI_STDCALL brlapi_getPacketTypeName (brlapi_packetType_t type)
Get plain packet type β¨
brlapi_getPacketTypeName() returns the plain packet type name corresponding to its argument.
It references BRLAPI_STDCALL.
πΈ void BRLAPI_STDCALL brlapi_perror (const char * s)
Print a BrlAPI error message π
brlapi_perror() reads brlapi_error, and acts just like perror().
It references BRLAPI_STDCALL.
πΈ brlapi_exceptionHandler_t BRLAPI_STDCALL brlapi_setExceptionHandler (brlapi_exceptionHandler_t handler)
Set a new exception handler π
brlapi_setExceptionHandler() replaces the previous exception handler with the handler parameter. The previous exception handler is returned, which is how you make chaining error handlers possible. Cute, right?
β οΈ Heads up bestie: the default handler just prints the exception and abort()s. Like, it literally ends the whole program. So maybe don't rely on it if you're not about that life. π
It references BRLAPI_STDCALL.
πΈ const char *BRLAPI_STDCALL brlapi_strerror (const brlapi_error_t * error)
Get plain error message π
brlapi_strerror() returns the plain error message corresponding to its argument.
π¨ Two things, and they matter: since the message is a constant string, the application must not free it. Also, this makes it unsafe in threaded environments β brlapi_strerror_r() should be used instead in that case. iykyk.
It references BRLAPI_STDCALL.
πΈ size_t BRLAPI_STDCALL brlapi_strerror_r (const brlapi_error_t * error, char * buf, size_t buflen)
Store plain error message πΎ
brlapi_strerror_r() stores the plain error message corresponding to its error argument. buflen has to be set to the size of buf, and brlapi_strerror_r() will store at most buflen bytes in buf. If buflen is not large enough for the whole error message, it will be truncated β but a trailing \0 character will still be set at buf[buflen-1]. Safety first, always. π«Ά
Returns
- the number of characters that should have been stored in
buf(without the trailing\0character). A value greater or equal tobuflenthus means that the output was truncated.
If buflen is set to 0, buf can be set to NULL, and brlapi_strerror_r will thus only return the number of characters that would have been stored (without the trailing \0 character). Size-probing era, we love to see it. π₯
It references BRLAPI_STDCALL.
πΈ int BRLAPI_STDCALL brlapi_strexception (char * buffer, size_t bufferSize, int error, brlapi_packetType_t type, const void * packet, size_t packetSize)
Describes an exception π
brlapi_strexception() puts a text describing the given exception in buffer.
The beginning of the guilty packet is dumped as a sequence of hex bytes. Yes bestie, it's naming names. π
Returns
- the size of the text describing the exception, following
snprintf()'s semantics.
It references BRLAPI_STDCALL.
π¦ Variable Documentation π¦
π const char* brlapi_errfun [extern]
Shorthand for brlapi_error.errfun
π const char* brlapi_errlist[] [extern]
Error message list π
These are the string constants used by brlapi_perror().
π enum brlapi_error brlapi_errno [extern]
Shorthand for brlapi_error.errno
π brlapi_error_t brlapi_error [extern]
Global variable brlapi_error π
brlapi_error is a global left-value containing the last error information. Its errno field is not reset to BRLAPI_ERROR_SUCCESS on success β so don't go assuming a clean slate, okay? π
This information may be copied in brlapi_error_t variables for later use with the brlapi_strerror function.
π int brlapi_gaierrno [extern]
Shorthand for brlapi_error.gaierrno
π int brlapi_libcerrno [extern]
Shorthand for brlapi_error.libcerrno
π const int brlapi_nerr [extern]
Number of error messages π’
π Author π
Generated automatically by Doxygen for BrlAPI from the source code.
And that's a wrap on brlapi_error(3), bestie!! π This whole thing came from BrlAPI, Version 0.8, and it's the brlapi_error(3) page β generated straight from the source code by Doxygen. Slay, stay safe, and always check your brlapi_error πβ¨π¦
π¦ where this page comes from
- fedora 43: brlapi-devel 0.8.7-4.fc43 Β· LGPL-2.0-or-later AND LGPL-2.1-or-later AND GPL-2.0-or-later
- fedora 43: brlapi-devel 0.8.7-4.fc43 Β· LGPL-2.0-or-later AND LGPL-2.1-or-later AND GPL-2.0-or-later
- fedora 44: brlapi-devel 0.8.7-8.fc44 Β· LGPL-2.0-or-later AND LGPL-2.1-or-later AND GPL-2.0-or-later
- fedora 44: brlapi-devel 0.8.7-8.fc44 Β· LGPL-2.0-or-later AND LGPL-2.1-or-later AND GPL-2.0-or-later
- opensuse-leap 16.0: brlapi-devel 6.8-160000.2.2 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: brlapi-devel 6.8-160000.2.2 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: brlapi-devel 6.8-160000.2.2 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: brlapi-devel 6.8-160000.2.2 Β· LGPL-2.1-or-later
- ubuntu resolute: libbrlapi-dev 6.7-1ubuntu6
- ubuntu stonking: libbrlapi-dev 6.9.1+repack-1ubuntu1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms