It would be nice to have an API similar to strerror to get textual descriptions of error codes so applications can show something meaningful to users in error messages.
This was already implemented ad-hoc in the .NET bindings, see here: https://github.com/mozilla/DeepSpeech/blob/0b82c751db58d9d2d90e861f9af04e671fd2ab41/native_client/dotnet/DeepSpeechClient/DeepSpeech.cs#L86-L125
Steps to fix this would be roughly:
Add a new API to native_client/deepspeech.h, something like:
char* DS_ErrorCodeToErrorMessage(int aErrorCode);
And then in native_client/deepspeech.cc, implement the function by returning the appropriate error message. The strings can be static, inlined directly in the source code. The documentation for DS_ErrorCodeToErrorMessage should indicate that the returned pointers are read only and MUST not be deallocated or modified.
Feel free to ask any questions if any of this is confusing.
Next steps would then be to expose this API to our language bindings, as well as make use of it in the .NET binding instead of having its own list there.
I would like to work on this issue!
I would like to work on this issue!
You should have all the informations requires already here. Please feel free to ask for clarification if required.
Thank You @lissyx
@reuben @lissyx Shouldn't be the argument of function
```cpp
char* DS_ErrorCodeToErrorMessage(int aErrorCode);
be
```cpp
char* DS_ErrorCodeToErrorMessage(DeepSpeech_Error_Codes aErrorCode);
As in deepspeech.h error codes are in enum DeepSpeech_Error_Codes
The C language standard does not guarantee the underlying size of an enum, so we could end up with nasty ABI compatibility issues due to compiler mismatches. int is safer in that regard.
Ok @reuben thanks.
The second part of this issue is making sure our bindings in the tree use the new API. There are four bindings in the three:
Here's a rough idea for how to do this for each one of them:
@imskr are you interested in also taking on this part?
Yes I would like to take this, thanks.
@reuben In python: Do I have to add all types of errors mentioned in API in __init__ function of both Model and Stream class here ?
@imskr you don't need to duplicate the list of errors anywhere. Just make sure whenever we report errors, instead of just showing the error number we also include a textual description by calling the new function you added in #2794.
Should I remove the raise statement and add the DS_ErrorCodeToErrorMessage function here ?
Having little confusion how do i use the DS_ErrorCodeToErrorMessage in __init__.py although i have added it in impli.i @reuben
@imskr You could, instead of throwing an exception with only the error code
status, impl = deepspeech.impl.CreateModel(model_path)
if status != 0:
raise RuntimeError("CreateModel failed with error code 0x{:X}".format(status))
throw an exception with the error code and textual description. Something like
status, impl = deepspeech.impl.CreateModel(model_path)
if status != 0:
status_message = deepspeech.impl.ErrorCodeToErrorMessage(status)
raise RuntimeError("CreateModel failed with error message {} with error code 0x{:X}".format(status_message, status))
Ok, Thank You @kdavis-mozilla
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
I would like to work on this issue!