com_select() callback: Return negative on errors.
authorAndre Noll <maan@tuebingen.mpg.de>
Sun, 5 Apr 2015 00:58:35 +0000 (00:58 +0000)
committerAndre Noll <maan@tuebingen.mpg.de>
Wed, 12 Aug 2015 21:23:47 +0000 (23:23 +0200)
afs.c

diff --git a/afs.c b/afs.c
index 4bc7871..a5ec7b2 100644 (file)
--- a/afs.c
+++ b/afs.c
@@ -501,6 +501,7 @@ static int activate_mood_or_playlist(char *arg, int *num_admissible)
        enum play_mode mode;
        int ret;
 
+       PARA_INFO_LOG("new playlist: %s\n", arg);
        if (!arg) {
                ret = change_current_mood(NULL); /* always successful */
                mode = PLAY_MODE_MOOD;
@@ -602,31 +603,32 @@ static int com_select_callback(int fd, const struct osl_object *query)
 
        ret = clear_score_table();
        if (ret < 0) {
-               para_printf(&pb, "%s\n", para_strerror(-ret));
-               goto out;
+               para_printf(&pb, "could not clear score table: %s\n",
+                       para_strerror(-ret));
+               return ret;
        }
        if (current_play_mode == PLAY_MODE_MOOD)
                close_current_mood();
        else
                playlist_close();
        ret = activate_mood_or_playlist(arg, &num_admissible);
-       if (ret < 0) {
-               para_printf(&pb, "%s\nswitching back to %s\n",
-                       para_strerror(-ret), current_mop?
-                       current_mop : "dummy");
-               ret = activate_mood_or_playlist(current_mop, &num_admissible);
-               if (ret < 0) {
-                       para_printf(&pb, "failed (%s), switching to dummy\n",
-                               para_strerror(-ret));
-                       activate_mood_or_playlist(NULL, &num_admissible);
-               }
-       } else
-               para_printf(&pb, "activated %s (%d admissible files)\n",
-                       current_mop?  current_mop : "dummy mood",
-                       num_admissible);
+       if (ret >= 0)
+               goto out;
+       para_printf(&pb, "could not activate %s: %s\n"
+               "switching back to %s\n",
+               arg, para_strerror(-ret), current_mop? current_mop : "dummy");
+       /* ignore subsequent errors (but log them) */
+       ret = activate_mood_or_playlist(current_mop, &num_admissible);
+       if (ret >= 0)
+               goto out;
+       para_printf(&pb, "could not activate %s: %s\nswitching to dummy\n",
+               current_mop, para_strerror(-ret));
+       activate_mood_or_playlist(NULL, &num_admissible);
 out:
+       para_printf(&pb, "activated %s (%d admissible files)\n",
+               current_mop? current_mop : "dummy mood", num_admissible);
        flush_and_free_pb(&pb);
-       return 0;
+       return ret;
 }
 
 int com_select(struct command_context *cc)