-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added implementation of DS_ErrorCodeToErrorMessage #2794
Conversation
No Taskcluster jobs started for this pull requestThe `allowPullRequests` configuration for this repository (in `.taskcluster.yml` on the
default branch) does not allow starting tasks for this pull request. |
@reuben I have added the function. Now, what should I add further to it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I have a few suggestions for better phrasing, and the function needs to be documented in deepspeech.h
.
@reuben @imskr Note that the way these strings are created, in static memory and not the heap, contradicts with the documentation of People will likely not catch this subtle difference and try to call |
Returning an allocated copy is unfortunate in this case because for getting the error string there are basically two main cases: Case 1, abort entire program: int err = DS_SomeAPI();
if (err != 0) {
fprintf(stderr, "DeepSpeech error: %s\n", DS_ErrorCodeToErrorString(err));
exit(1);
} In this case freeing the string is pointless since you're Case 2, error propagation: int err = DS_SomeAPI();
if (err != 0) {
char* ds_copy = DS_ErrorCodeToErrorMessage(err);
char* our_copy = strdup(ds_copy); // caller shouldn't have to know about DS API
DS_FreeString(ds_copy);
return MyErrorAbstraction(STT_ERROR, our_copy);
} In this case, if we allocate the error string, we force applications to immediately copy it again with their own allocator, or we force them to include custom allocator/deleter support in their error abstraction, because otherwise some caller far away is going to have to know about int err = DS_SomeAPI();
if (err != 0) {
return MyErrorAbstraction(STT_ERROR, DS_ErrorCodeToErrorMessage(err));
} |
Granted, this is also true for |
Yeah it's not ideal. But having this mixed API where some strings need to be freed with DS_FreeString() and some strings do not need to be freed with DS_FreeString() is also not ideal as it's confusing. As for Case1, your example is true of very simply programs and applications, but for production integrations, think a GUI based application, you would never just exit if someone encountered a |
How should I proceed with |
@imskr please return a copy of the string using |
Okay, thank you @reuben @kdavis-mozilla |
Is it good now? @reuben |
@imskr thanks for the PR! |
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. |
Implementation of an API to get textual descriptions of error codes.
Fixes #2773