Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

improved error output of CommandExecutor and Tcl

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.