[Orxonox-commit 4165] r8836 - code/branches/output/src/libraries/core/command
landauf at orxonox.net
landauf at orxonox.net
Sat Aug 13 19:30:04 CEST 2011
Author: landauf
Date: 2011-08-13 19:30:04 +0200 (Sat, 13 Aug 2011)
New Revision: 8836
Modified:
code/branches/output/src/libraries/core/command/CommandEvaluation.cc
code/branches/output/src/libraries/core/command/CommandExecutor.cc
code/branches/output/src/libraries/core/command/CommandExecutor.h
code/branches/output/src/libraries/core/command/Shell.cc
code/branches/output/src/libraries/core/command/TclBind.cc
code/branches/output/src/libraries/core/command/TclThreadManager.cc
Log:
improved error output of CommandExecutor and Tcl
Modified: code/branches/output/src/libraries/core/command/CommandEvaluation.cc
===================================================================
--- code/branches/output/src/libraries/core/command/CommandEvaluation.cc 2011-08-11 22:48:23 UTC (rev 8835)
+++ code/branches/output/src/libraries/core/command/CommandEvaluation.cc 2011-08-13 17:30:04 UTC (rev 8836)
@@ -130,7 +130,7 @@
*error = CommandExecutor::Success;
if (!this->execCommand_)
- *error = CommandExecutor::Error;
+ *error = CommandExecutor::Inexistent;
else if (!this->execCommand_->isActive())
*error = CommandExecutor::Deactivated;
else if (!this->execCommand_->hasAccess())
@@ -186,7 +186,7 @@
{
if (bPrintError)
orxout(internal_error, context::commands) << "Can't evaluate arguments, no console command assigned." << endl;
- return CommandExecutor::Error;
+ return CommandExecutor::Inexistent;
}
int error;
Modified: code/branches/output/src/libraries/core/command/CommandExecutor.cc
===================================================================
--- code/branches/output/src/libraries/core/command/CommandExecutor.cc 2011-08-11 22:48:23 UTC (rev 8835)
+++ code/branches/output/src/libraries/core/command/CommandExecutor.cc 2011-08-13 17:30:04 UTC (rev 8836)
@@ -68,10 +68,12 @@
@param useTcl If true, the command is passed to tcl (see TclBind)
@return Returns the error-code (see @ref CommandExecutorErrorCodes "error codes")
*/
- /* static */ int CommandExecutor::execute(const std::string& command, bool useTcl)
+ /* static */ int CommandExecutor::execute(const std::string& command, bool useTcl, bool printErrors)
{
int error;
CommandExecutor::queryMT(command, &error, useTcl);
+ if (error)
+ orxout(user_error) << "Can't execute \"" << command << "\", " << CommandExecutor::getErrorDescription(error) << ". (execute)" << endl;
return error;
}
@@ -84,10 +86,13 @@
*/
/* static */ MultiType CommandExecutor::queryMT(const std::string& command, int* error, bool useTcl)
{
+ MultiType result;
+ int error_internal;
+
if (useTcl)
{
// pass the command to tcl
- return TclBind::eval(command, error);
+ result = TclBind::eval(command, &error_internal);
}
else
{
@@ -107,8 +112,15 @@
}
// query the command and return its return-value
- return evaluation.query(error);
+ result = evaluation.query(&error_internal);
}
+
+ if (error)
+ *error = error_internal;
+ else if (error_internal)
+ orxout(user_error) << "Can't execute \"" << command << "\", " << CommandExecutor::getErrorDescription(error_internal) << ". (query)" << endl;
+
+ return result;
}
/**
@@ -171,6 +183,23 @@
}
/**
+ @brief Returns a description of the error code.
+ @param error The error code
+ */
+ /* static */ std::string CommandExecutor::getErrorDescription(int error)
+ {
+ switch (error)
+ {
+ case CommandExecutor::Inexistent: return "command doesn't exist";
+ case CommandExecutor::Incomplete: return "not enough arguments given";
+ case CommandExecutor::Deactivated: return "command is not active";
+ case CommandExecutor::Denied: return "access denied";
+ case CommandExecutor::Error: return "an error occurred";
+ default: return "";
+ }
+ }
+
+ /**
@brief Gets an evaluated command from the cache.
@param command The command that should be looked up in the cache
@param evaluation Reference to a CommandEvaluation that will be used to return the cached evaluation.
Modified: code/branches/output/src/libraries/core/command/CommandExecutor.h
===================================================================
--- code/branches/output/src/libraries/core/command/CommandExecutor.h 2011-08-11 22:48:23 UTC (rev 8835)
+++ code/branches/output/src/libraries/core/command/CommandExecutor.h 2011-08-13 17:30:04 UTC (rev 8836)
@@ -110,7 +110,7 @@
{
// tolua_end
public:
- static int execute(const std::string& command, bool useTcl = true); // tolua_export
+ static int execute(const std::string& command, bool useTcl = true, bool printErrors = true); // tolua_export
static MultiType queryMT(const std::string& command, int* error = 0, bool useTcl = true);
static std::string query(const std::string& command, int* error = 0, bool useTcl = true); // tolua_export
@@ -118,11 +118,14 @@
static CommandEvaluation evaluate(const std::string& command);
static const int Success = 0; ///< Error code for "success" (or no error)
- static const int Error = 1; ///< Error code if the command doesn't exist
+ static const int Inexistent = 1; ///< Error code if the command doesn't exist
static const int Incomplete = 2; ///< Error code if the command needs more arguments
static const int Deactivated = 3; ///< Error code if the command is not active
static const int Denied = 4; ///< Error code if the command needs a different access level
+ static const int Error = 5; ///< Error code if the command returned an error
+ static std::string getErrorDescription(int error);
+
static MultiType unhide(const std::string& command);
static void alias(const std::string& alias, const std::string& command);
static void _autocomplete(const std::string& group, const std::string& name) {} ///< Pseudo console command used whenever no real command is available. In these cases this command provides auto-completion for console commands and groups.
Modified: code/branches/output/src/libraries/core/command/Shell.cc
===================================================================
--- code/branches/output/src/libraries/core/command/Shell.cc 2011-08-11 22:48:23 UTC (rev 8835)
+++ code/branches/output/src/libraries/core/command/Shell.cc 2011-08-13 17:30:04 UTC (rev 8836)
@@ -388,19 +388,9 @@
int error;
const std::string& result = CommandExecutor::query(this->inputBuffer_->get(), &error);
if (error)
- {
- switch (error)
- {
- case CommandExecutor::Error: this->addOutput("Error: Can't execute \"" + this->inputBuffer_->get() + "\", command doesn't exist. (S)", UserError); break;
- case CommandExecutor::Incomplete: this->addOutput("Error: Can't execute \"" + this->inputBuffer_->get() + "\", not enough arguments given. (S)", UserError); break;
- case CommandExecutor::Deactivated: this->addOutput("Error: Can't execute \"" + this->inputBuffer_->get() + "\", command is not active. (S)", UserError); break;
- case CommandExecutor::Denied: this->addOutput("Error: Can't execute \"" + this->inputBuffer_->get() + "\", access denied. (S)", UserError); break;
- }
- }
+ this->addOutput("Error: Can't execute \"" + this->inputBuffer_->get() + "\", " + CommandExecutor::getErrorDescription(error) + ". (Shell)", UserError);
else if (result != "")
- {
this->addOutput(result, Result);
- }
this->clearInput();
}
Modified: code/branches/output/src/libraries/core/command/TclBind.cc
===================================================================
--- code/branches/output/src/libraries/core/command/TclBind.cc 2011-08-11 22:48:23 UTC (rev 8835)
+++ code/branches/output/src/libraries/core/command/TclBind.cc 2011-08-13 17:30:04 UTC (rev 8836)
@@ -186,17 +186,13 @@
else
error = evaluation.execute();
- switch (error)
+ if (error)
{
- case CommandExecutor::Error: orxout(user_error) << "Can't execute command \"" << command << "\", command doesn't exist. (B)" << endl; break;
- case CommandExecutor::Incomplete: orxout(user_error) << "Can't execute command \"" << command << "\", not enough arguments given. (B)" << endl; break;
- case CommandExecutor::Deactivated: orxout(user_error) << "Can't execute command \"" << command << "\", command is not active. (B)" << endl; break;
- case CommandExecutor::Denied: orxout(user_error) << "Can't execute command \"" << command << "\", access denied. (B)" << endl; break;
+ orxout(user_error) << "Can't execute command \"" << command << "\", " + CommandExecutor::getErrorDescription(error) + ". (TclBind)" << endl;
+ if (error == CommandExecutor::Inexistent)
+ orxout(user_info) << "Did you mean \"" << evaluation.getCommandSuggestion() << "\"?" << endl;
}
- if (error == CommandExecutor::Error)
- orxout(user_info) << "Did you mean \"" << evaluation.getCommandSuggestion() << "\"?" << endl;
-
return result;
}
Modified: code/branches/output/src/libraries/core/command/TclThreadManager.cc
===================================================================
--- code/branches/output/src/libraries/core/command/TclThreadManager.cc 2011-08-11 22:48:23 UTC (rev 8835)
+++ code/branches/output/src/libraries/core/command/TclThreadManager.cc 2011-08-13 17:30:04 UTC (rev 8836)
@@ -448,13 +448,8 @@
TclThreadManager::debug("TclThread_query -> CE: " + command);
int error;
output = CommandExecutor::query(command, &error, false);
- switch (error)
- {
- case CommandExecutor::Error: TclThreadManager::error("Can't execute command \"" + command + "\", command doesn't exist. (T)"); break;
- case CommandExecutor::Incomplete: TclThreadManager::error("Can't execute command \"" + command + "\", not enough arguments given. (T)"); break;
- case CommandExecutor::Deactivated: TclThreadManager::error("Can't execute command \"" + command + "\", command is not active. (T)"); break;
- case CommandExecutor::Denied: TclThreadManager::error("Can't execute command \"" + command + "\", access denied. (T)"); break;
- }
+ if (error)
+ TclThreadManager::error("Can't execute command \"" + command + "\", " + CommandExecutor::getErrorDescription(error) + ". (TclThreadManager)");
}
else
{
More information about the Orxonox-commit
mailing list