Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8836 for code


Ignore:
Timestamp:
Aug 13, 2011, 7:30:04 PM (13 years ago)
Author:
landauf
Message:

improved error output of CommandExecutor and Tcl

Location:
code/branches/output/src/libraries/core/command
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/output/src/libraries/core/command/CommandEvaluation.cc

    r8806 r8836  
    131131
    132132            if (!this->execCommand_)
    133                 *error = CommandExecutor::Error;
     133                *error = CommandExecutor::Inexistent;
    134134            else if (!this->execCommand_->isActive())
    135135                *error = CommandExecutor::Deactivated;
     
    187187            if (bPrintError)
    188188                orxout(internal_error, context::commands) << "Can't evaluate arguments, no console command assigned." << endl;
    189             return CommandExecutor::Error;
     189            return CommandExecutor::Inexistent;
    190190        }
    191191
  • code/branches/output/src/libraries/core/command/CommandExecutor.cc

    r8806 r8836  
    6969        @return Returns the error-code (see @ref CommandExecutorErrorCodes "error codes")
    7070    */
    71     /* static */ int CommandExecutor::execute(const std::string& command, bool useTcl)
     71    /* static */ int CommandExecutor::execute(const std::string& command, bool useTcl, bool printErrors)
    7272    {
    7373        int error;
    7474        CommandExecutor::queryMT(command, &error, useTcl);
     75        if (error)
     76            orxout(user_error) << "Can't execute \"" << command << "\", " << CommandExecutor::getErrorDescription(error) << ". (execute)" << endl;
    7577        return error;
    7678    }
     
    8587    /* static */ MultiType CommandExecutor::queryMT(const std::string& command, int* error, bool useTcl)
    8688    {
     89        MultiType result;
     90        int error_internal;
     91
    8792        if (useTcl)
    8893        {
    8994            // pass the command to tcl
    90             return TclBind::eval(command, error);
     95            result = TclBind::eval(command, &error_internal);
    9196        }
    9297        else
     
    108113
    109114            // query the command and return its return-value
    110             return evaluation.query(error);
    111         }
     115            result = evaluation.query(&error_internal);
     116        }
     117
     118        if (error)
     119            *error = error_internal;
     120        else if (error_internal)
     121            orxout(user_error) << "Can't execute \"" << command << "\", " << CommandExecutor::getErrorDescription(error_internal) << ". (query)" << endl;
     122
     123        return result;
    112124    }
    113125
     
    172184
    173185    /**
     186        @brief Returns a description of the error code.
     187        @param error The error code
     188    */
     189    /* static */ std::string CommandExecutor::getErrorDescription(int error)
     190    {
     191        switch (error)
     192        {
     193            case CommandExecutor::Inexistent:  return "command doesn't exist";
     194            case CommandExecutor::Incomplete:  return "not enough arguments given";
     195            case CommandExecutor::Deactivated: return "command is not active";
     196            case CommandExecutor::Denied:      return "access denied";
     197            case CommandExecutor::Error:       return "an error occurred";
     198            default: return "";
     199        }
     200    }
     201
     202    /**
    174203        @brief Gets an evaluated command from the cache.
    175204        @param command The command that should be looked up in the cache
  • code/branches/output/src/libraries/core/command/CommandExecutor.h

    r7401 r8836  
    111111// tolua_end
    112112        public:
    113             static int execute(const std::string& command, bool useTcl = true); // tolua_export
     113            static int execute(const std::string& command, bool useTcl = true, bool printErrors = true); // tolua_export
    114114
    115115            static MultiType queryMT(const std::string& command, int* error = 0, bool useTcl = true);
     
    119119
    120120            static const int Success = 0;       ///< Error code for "success" (or no error)
    121             static const int Error = 1;         ///< Error code if the command doesn't exist
     121            static const int Inexistent = 1;    ///< Error code if the command doesn't exist
    122122            static const int Incomplete = 2;    ///< Error code if the command needs more arguments
    123123            static const int Deactivated = 3;   ///< Error code if the command is not active
    124124            static const int Denied = 4;        ///< Error code if the command needs a different access level
     125            static const int Error = 5;         ///< Error code if the command returned an error
     126
     127            static std::string getErrorDescription(int error);
    125128
    126129            static MultiType unhide(const std::string& command);
  • code/branches/output/src/libraries/core/command/Shell.cc

    r8834 r8836  
    389389        const std::string& result = CommandExecutor::query(this->inputBuffer_->get(), &error);
    390390        if (error)
    391         {
    392             switch (error)
    393             {
    394                 case CommandExecutor::Error:       this->addOutput("Error: Can't execute \"" + this->inputBuffer_->get() + "\", command doesn't exist. (S)", UserError); break;
    395                 case CommandExecutor::Incomplete:  this->addOutput("Error: Can't execute \"" + this->inputBuffer_->get() + "\", not enough arguments given. (S)", UserError); break;
    396                 case CommandExecutor::Deactivated: this->addOutput("Error: Can't execute \"" + this->inputBuffer_->get() + "\", command is not active. (S)", UserError); break;
    397                 case CommandExecutor::Denied:      this->addOutput("Error: Can't execute \"" + this->inputBuffer_->get() + "\", access denied. (S)", UserError); break;
    398             }
    399         }
     391            this->addOutput("Error: Can't execute \"" + this->inputBuffer_->get() + "\", " + CommandExecutor::getErrorDescription(error) + ". (Shell)", UserError);
    400392        else if (result != "")
    401         {
    402393            this->addOutput(result, Result);
    403         }
    404394
    405395        this->clearInput();
  • code/branches/output/src/libraries/core/command/TclBind.cc

    r8806 r8836  
    187187            error = evaluation.execute();
    188188
    189         switch (error)
    190         {
    191             case CommandExecutor::Error:       orxout(user_error) << "Can't execute command \"" << command << "\", command doesn't exist. (B)" << endl; break;
    192             case CommandExecutor::Incomplete:  orxout(user_error) << "Can't execute command \"" << command << "\", not enough arguments given. (B)" << endl; break;
    193             case CommandExecutor::Deactivated: orxout(user_error) << "Can't execute command \"" << command << "\", command is not active. (B)" << endl; break;
    194             case CommandExecutor::Denied:      orxout(user_error) << "Can't execute command \"" << command << "\", access denied. (B)" << endl; break;
    195         }
    196 
    197         if (error == CommandExecutor::Error)
    198             orxout(user_info) << "Did you mean \"" << evaluation.getCommandSuggestion() << "\"?" << endl;
     189        if (error)
     190        {
     191            orxout(user_error) << "Can't execute command \"" << command << "\", " + CommandExecutor::getErrorDescription(error) + ". (TclBind)" << endl;
     192            if (error == CommandExecutor::Inexistent)
     193                orxout(user_info) << "Did you mean \"" << evaluation.getCommandSuggestion() << "\"?" << endl;
     194        }
    199195
    200196        return result;
  • code/branches/output/src/libraries/core/command/TclThreadManager.cc

    r8806 r8836  
    449449                        int error;
    450450                        output = CommandExecutor::query(command, &error, false);
    451                         switch (error)
    452                         {
    453                             case CommandExecutor::Error:       TclThreadManager::error("Can't execute command \"" + command + "\", command doesn't exist. (T)"); break;
    454                             case CommandExecutor::Incomplete:  TclThreadManager::error("Can't execute command \"" + command + "\", not enough arguments given. (T)"); break;
    455                             case CommandExecutor::Deactivated: TclThreadManager::error("Can't execute command \"" + command + "\", command is not active. (T)"); break;
    456                             case CommandExecutor::Denied:      TclThreadManager::error("Can't execute command \"" + command + "\", access denied. (T)"); break;
    457                         }
     451                        if (error)
     452                            TclThreadManager::error("Can't execute command \"" + command + "\", " + CommandExecutor::getErrorDescription(error) + ". (TclThreadManager)");
    458453                    }
    459454                    else
Note: See TracChangeset for help on using the changeset viewer.