Deepspeech: [Good First Bug] Implement an API to get textual descriptions of error codes

Created on 19 Feb 2020  路  15Comments  路  Source: mozilla/DeepSpeech

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.

good first bug help wanted

Most helpful comment

I would like to work on this issue!

All 15 comments

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:

  • Python: in the object oriented wrapper classes (code here), add checks around every fallible API call as well as using the message strings when raising an exception instead of using the numeric code. You'll also have to add the new function to the list here to make sure the strings are deallocated.
  • JavaScript: same as above. Wrapper classes are here, list of functions that return newly allocated strings is here.
  • .NET: already has its own handling, which was used as the source for the textual descriptions. Needs to be updated to use the new API. The new function needs to be added in NativeImp.cs, and then it can be used from DeepSpeech.EvaluateResultCode.
  • Java: function has to be added to the list here. Actually using it is part of a separate issue, #2701.

@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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yoann1995 picture yoann1995  路  49Comments

stes picture stes  路  154Comments

khu834 picture khu834  路  48Comments

mdasari823 picture mdasari823  路  39Comments

MalikMahnoor picture MalikMahnoor  路  79Comments