errstr contains complete error string when M code called from other languages raises an error
Final Release Note
When an error occurs in M code called from other languages, the errstr
error string, the second parameter in the Simple API for multi-threaded applications, is filled in appropriately. Previously, it was either the empty string (""
) for C and most languages, or the template for the error message without the fields filled in for Go. This was discovered in the YottaDB development environment and never reported by a user. [#785 (closed)]
Description
While this issue was noted with the Go wrapper, it affects all wrappers/languages. If a non-M language makes a call to either ydb_ci_t() or ydb_cip_t() and has an error occur in the M code, the caller gets the return code of the error but not the error text. The only 2 ways to fetch the error text are:
- Calling ydb_message_t() with the error value to fetch the message text.
- Calling ydb_zstatus() to fetch the $ZSTATUS value.
The problem is ydb_message_t() will fetch a message with no substitutions in it so for example, as it was in this case, an LVUNDEF message did not have the undefined variable name filled in so was largely useless. The other method of using ydb_zstatus() to fetch the $ZSTATUS value which would have substitutions is that in a multi-threaded environment, the engine lock that single threads requests has been released by the time the call returns so it is possible for the error message to be overwritten.
The changes for this issue will detect that an error occurred in ydb_ci_t() or ydb_cip_t() BEFORE the engine lock is released and if the errstr value is still NULL (length of message now initialized before the M code is actually driven), then the value of $ZSTATUS is copied into errstr BEFORE the engine lock is released.
Draft Release Note
Wrapper for Go and other languages now have the error string (errstr) filled in appropriately if an error occurs while M code is running. Previously, the returned error message was either NULL, or in the case of the Go wrapper, had the message without any value substitutions in it making many messages not very useful.