Skip to content

Commit

Permalink
piano: Do not return empty explanation.
Browse files Browse the repository at this point in the history
Instead return NULL and let the client handle it.
  • Loading branch information
PromyLOPh committed Mar 29, 2024
1 parent c76bcb2 commit ee735ee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/libpiano/response.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,8 @@ PianoReturn_t PianoResponse (PianoHandle_t *ph, PianoRequest_t *req) {
assert (reqData != NULL);

json_object *explanations;
if (json_object_object_get_ex (result, "explanations", &explanations)) {
if (json_object_object_get_ex (result, "explanations", &explanations) &&
json_object_array_length (explanations) > 0) {
reqData->retExplain = malloc (strSize *
sizeof (*reqData->retExplain));
strncpy (reqData->retExplain, "We're playing this track "
Expand Down
8 changes: 6 additions & 2 deletions src/ui_act.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,12 @@ BarUiActCallback(BarUiActExplain) {

BarUiMsg (&app->settings, MSG_INFO, "Receiving explanation... ");
if (BarUiActDefaultPianoCall (PIANO_REQUEST_EXPLAIN, &reqData)) {
BarUiMsg (&app->settings, MSG_INFO, "%s\n", reqData.retExplain);
free (reqData.retExplain);
if (reqData.retExplain == NULL) {
BarUiMsg (&app->settings, MSG_ERR, "No explanation provided.\n");
} else {
BarUiMsg (&app->settings, MSG_INFO, "%s\n", reqData.retExplain);
free (reqData.retExplain);
}
}
BarUiActDefaultEventcmd ("songexplain");
}
Expand Down

0 comments on commit ee735ee

Please sign in to comment.