include host error text in string returned by Pa_GetErrorText on paUnanticipatedHostError
[Trac: Originally assigned to none]
Pa_GetErrorText currently returns a generic error message "Unanticipated host error" when the host api returns paUnanticipatedHostError. More detailed info is available in Pa_GetLastHostErrorInfo() but we could return the host error string from Pa_GetErrorText too. It would improve usability and ease debugging.
Pa_GetErrorText currently returns a generic error message "Unanticipated host error" when the host api returns paUnanticipatedHostError. More detailed info is available in Pa_GetLastHostErrorInfo() but we could return the host error string from Pa_GetErrorText too. It would improve usability and ease debugging.
Leave a comment
Use a static char buffer inside Pa_GetErrorText to assemble an error message that includes the host error. Something like:
Untested code, Pa_GetErrorText() in pa_front.c
{{{#!C
case paUnanticipatedHostError:
const PaHostErrorInfo hostErrorInfo = Pa_GetLastHostErrorInfo();
if( hostErrorInfo ){
PaHostApiIndex hostApiIndex = Pa_HostApiTypeIdToHostApiIndex(hostErrorInfo->hostApiType);
if( hostApiIndex >= 0 ){
const PaHostApiInfo hostApiInfo = Pa_GetHostApiInfo( hostApiIndex );
if( hostApiInfo ){
static s[1000]; / static so it persists after we return */
snprintf( s, 1000, "Unanticipated host error: %s (%d): %s",
hostApiInfo->name, hostErrorInfo->errorText, hostErrorInfo->errorCode );
result = s;
break;
}
}
}
/ if any of the above fails, we just return a generic message */
result = "Unanticipated host error";
break;
}}}
Of course you also need to work out how to test it properly :-)
Untested code, Pa_GetErrorText() in pa_front.c
{{{#!C
case paUnanticipatedHostError:
const PaHostErrorInfo hostErrorInfo = Pa_GetLastHostErrorInfo();
if( hostErrorInfo ){
PaHostApiIndex hostApiIndex = Pa_HostApiTypeIdToHostApiIndex(hostErrorInfo->hostApiType);
if( hostApiIndex >= 0 ){
const PaHostApiInfo hostApiInfo = Pa_GetHostApiInfo( hostApiIndex );
if( hostApiInfo ){
static s[1000]; / static so it persists after we return */
snprintf( s, 1000, "Unanticipated host error: %s (%d): %s",
hostApiInfo->name, hostErrorInfo->errorText, hostErrorInfo->errorCode );
result = s;
break;
}
}
}
/ if any of the above fails, we just return a generic message */
result = "Unanticipated host error";
break;
}}}
Of course you also need to work out how to test it properly :-)