improve command prohibition error report
authorZachary T Welch <zw@superlucidity.net>
Sun, 29 Nov 2009 00:29:41 +0000 (16:29 -0800)
committerZachary T Welch <zw@superlucidity.net>
Tue, 1 Dec 2009 04:54:40 +0000 (20:54 -0800)
Ensures that the correct information gets displayed, depending on the
mode of the command being denied.  Fixes misreporting all commands as
needing to run "before 'init'".

src/helper/command.c

index 9b9c5ec0ee34f2ed16fbc6e6c8bd09b7ea0f5f03..dcad6a198e39ff9de78f6a740263f66af2ece812 100644 (file)
@@ -565,8 +565,16 @@ static int run_command(struct command_context *context,
 {
        if (!command_can_run(context, c))
        {
-               /* Config commands can not run after the config stage */
-               LOG_ERROR("The '%s' command must be used before 'init'.", c->name);
+               /* Many commands may be run only before/after 'init' */
+               const char *when;
+               switch (c->mode) {
+               case COMMAND_CONFIG: when = "before"; break;
+               case COMMAND_EXEC: when = "after"; break;
+               // handle the impossible with humor; it guarantees a bug report!
+               default: when = "if Cthulhu is summoned by"; break;
+               }
+               LOG_ERROR("The '%s' command must be used %s 'init'.",
+                               c->name, when);
                return ERROR_FAIL;
        }