labjack/C_CPP_LJM

LJM_ErrorToString is not consistent

Opened this issue · 1 comments

Hi there, I don't know if this is the best place to raise this issue, but the LJM library doesn't have available source so I'm putting this here.

The LJM_ErrorToString function does not consistently return the names of the LJME_* errors. For example, calling LJM_ErrorToString with LJME_NOERROR as an argument returns the string "LJ_SUCCESS", not the string "LJME_NOERROR". In addition, LJME_U3_NOT_SUPPORTED_BY_LJM, as well as _U6 and _U9, return strings including a description of the issue, while no other error codes do this.

LJ_SUCCESS is returned because it is the error string for code 0 defined in ljm_constants. LJM_ErrorToString reads ljm_constants.json to get the error messages. You can see the ljm_constants codes in the LJM User's Guide, installed on your local machine, or in our ljm_constants repo.

I am not sure if there is a particular reason why we define 0 as LJME_NO_ERROR in the header file and not ljm_constants, but it might be most useful to say that it happened because LabJackM.h is not generating error codes using ljm_constants. We have known about this limitation, I believe we are planning to do something with it, but we do not have a solid timeline for relevant changes.

It is intentional that only some error codes display the error message. The API will only return messages for the most common or important error codes. In the past, LabJack decided to define the maximum string size LJM_MAX_NAME_SIZE as 256 characters. Some error messages could potentially exceed this size, so our options are to clip messages if they exceed the max name size, change the API to increase the maximum name size, limit all error messages to 255 characters, or do what we do now with providing a limited set of messages. We will investigate these options, but right now it is a low priority for us.