diff options
author | Benoit Foucher <benoit@zeroc.com> | 2005-12-08 09:28:30 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2005-12-08 09:28:30 +0000 |
commit | 3fc8f08b1544a123fe1cefb1348154d7a29513b4 (patch) | |
tree | 9da2d13f42fd0063f94ed1bc24d6b7b8e07d6ae7 /cpp/src | |
parent | adding component files (diff) | |
download | ice-3fc8f08b1544a123fe1cefb1348154d7a29513b4.tar.bz2 ice-3fc8f08b1544a123fe1cefb1348154d7a29513b4.tar.xz ice-3fc8f08b1544a123fe1cefb1348154d7a29513b4.zip |
Improved error messages
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/IceGrid/Grammar.y | 132 | ||||
-rw-r--r-- | cpp/src/IceGrid/Parser.cpp | 72 | ||||
-rw-r--r-- | cpp/src/IceGrid/Parser.h | 3 |
3 files changed, 146 insertions, 61 deletions
diff --git a/cpp/src/IceGrid/Grammar.y b/cpp/src/IceGrid/Grammar.y index 7b4654161c3..cf0c7662fea 100644 --- a/cpp/src/IceGrid/Grammar.y +++ b/cpp/src/IceGrid/Grammar.y @@ -27,7 +27,7 @@ using namespace IceGrid; void yyerror(const char* s) { - parser->error(s); + parser->invalidCommand(s); } %} @@ -106,39 +106,39 @@ command { return 0; } -| ICE_GRID_APPLICATION ICE_GRID_ADD strings ';' +| ICE_GRID_APPLICATION ICE_GRID_ADD optional_strings ';' { parser->addApplication($3); } -| ICE_GRID_APPLICATION ICE_GRID_REMOVE strings ';' +| ICE_GRID_APPLICATION ICE_GRID_REMOVE optional_strings ';' { parser->removeApplication($3); } -| ICE_GRID_APPLICATION ICE_GRID_DIFF strings ';' +| ICE_GRID_APPLICATION ICE_GRID_DIFF optional_strings ';' { parser->diffApplication($3); } -| ICE_GRID_APPLICATION ICE_GRID_UPDATE strings ';' +| ICE_GRID_APPLICATION ICE_GRID_UPDATE optional_strings ';' { parser->updateApplication($3); } -| ICE_GRID_APPLICATION ICE_GRID_DESCRIBE strings ';' +| ICE_GRID_APPLICATION ICE_GRID_DESCRIBE optional_strings ';' { parser->describeApplication($3); } -| ICE_GRID_APPLICATION ICE_GRID_PATCH strings ';' +| ICE_GRID_APPLICATION ICE_GRID_PATCH optional_strings ';' { parser->patchApplication($3); } -| ICE_GRID_SERVER ICE_GRID_TEMPLATE ICE_GRID_DESCRIBE strings ';' +| ICE_GRID_SERVER ICE_GRID_TEMPLATE ICE_GRID_DESCRIBE optional_strings ';' { parser->describeServerTemplate($4); } -| ICE_GRID_SERVER ICE_GRID_TEMPLATE ICE_GRID_INSTANTIATE strings ';' +| ICE_GRID_SERVER ICE_GRID_TEMPLATE ICE_GRID_INSTANTIATE optional_strings ';' { parser->instantiateServerTemplate($4); } -| ICE_GRID_SERVICE ICE_GRID_TEMPLATE ICE_GRID_DESCRIBE strings ';' +| ICE_GRID_SERVICE ICE_GRID_TEMPLATE ICE_GRID_DESCRIBE optional_strings ';' { parser->describeServiceTemplate($4); } @@ -146,19 +146,19 @@ command { parser->listAllApplications(); } -| ICE_GRID_NODE ICE_GRID_DESCRIBE strings ';' +| ICE_GRID_NODE ICE_GRID_DESCRIBE optional_strings ';' { parser->describeNode($3); } -| ICE_GRID_NODE ICE_GRID_PING strings ';' +| ICE_GRID_NODE ICE_GRID_PING optional_strings ';' { parser->pingNode($3); } -| ICE_GRID_NODE ICE_GRID_LOAD strings ';' +| ICE_GRID_NODE ICE_GRID_LOAD optional_strings ';' { parser->printLoadNode($3); } -| ICE_GRID_NODE ICE_GRID_SHUTDOWN strings ';' +| ICE_GRID_NODE ICE_GRID_SHUTDOWN optional_strings ';' { parser->shutdownNode($3); } @@ -166,51 +166,51 @@ command { parser->listAllNodes(); } -| ICE_GRID_SERVER ICE_GRID_REMOVE strings ';' +| ICE_GRID_SERVER ICE_GRID_REMOVE optional_strings ';' { parser->removeServer($3); } -| ICE_GRID_SERVER ICE_GRID_DESCRIBE strings ';' +| ICE_GRID_SERVER ICE_GRID_DESCRIBE optional_strings ';' { parser->describeServer($3); } -| ICE_GRID_SERVER ICE_GRID_START strings ';' +| ICE_GRID_SERVER ICE_GRID_START optional_strings ';' { parser->startServer($3); } -| ICE_GRID_SERVER ICE_GRID_STOP strings ';' +| ICE_GRID_SERVER ICE_GRID_STOP optional_strings ';' { parser->stopServer($3); } -| ICE_GRID_SERVER ICE_GRID_PATCH strings ';' +| ICE_GRID_SERVER ICE_GRID_PATCH optional_strings ';' { parser->patchServer($3); } -| ICE_GRID_SERVER ICE_GRID_SIGNAL strings ';' +| ICE_GRID_SERVER ICE_GRID_SIGNAL optional_strings ';' { parser->signalServer($3); } -| ICE_GRID_SERVER ICE_GRID_STDOUT strings ';' +| ICE_GRID_SERVER ICE_GRID_STDOUT optional_strings ';' { parser->writeMessage($3, 1); } -| ICE_GRID_SERVER ICE_GRID_STDERR strings ';' +| ICE_GRID_SERVER ICE_GRID_STDERR optional_strings ';' { parser->writeMessage($3, 2); } -| ICE_GRID_SERVER ICE_GRID_STATE strings ';' +| ICE_GRID_SERVER ICE_GRID_STATE optional_strings ';' { parser->stateServer($3); } -| ICE_GRID_SERVER ICE_GRID_PID strings ';' +| ICE_GRID_SERVER ICE_GRID_PID optional_strings ';' { parser->pidServer($3); } -| ICE_GRID_SERVER ICE_GRID_ENABLE strings ';' +| ICE_GRID_SERVER ICE_GRID_ENABLE optional_strings ';' { parser->enableServer($3, true); } -| ICE_GRID_SERVER ICE_GRID_DISABLE strings ';' +| ICE_GRID_SERVER ICE_GRID_DISABLE optional_strings ';' { parser->enableServer($3, false); } @@ -218,11 +218,11 @@ command { parser->listAllServers(); } -| ICE_GRID_ADAPTER ICE_GRID_ENDPOINTS strings ';' +| ICE_GRID_ADAPTER ICE_GRID_ENDPOINTS optional_strings ';' { parser->endpointsAdapter($3); } -| ICE_GRID_ADAPTER ICE_GRID_REMOVE strings ';' +| ICE_GRID_ADAPTER ICE_GRID_REMOVE optional_strings ';' { parser->removeAdapter($3); } @@ -230,15 +230,15 @@ command { parser->listAllAdapters(); } -| ICE_GRID_OBJECT ICE_GRID_ADD strings ';' +| ICE_GRID_OBJECT ICE_GRID_ADD optional_strings ';' { parser->addObject($3); } -| ICE_GRID_OBJECT ICE_GRID_REMOVE strings ';' +| ICE_GRID_OBJECT ICE_GRID_REMOVE optional_strings ';' { parser->removeObject($3); } -| ICE_GRID_OBJECT ICE_GRID_FIND strings ';' +| ICE_GRID_OBJECT ICE_GRID_FIND optional_strings ';' { parser->findObject($3); } @@ -262,6 +262,76 @@ command { parser->showWarranty(); } +| ICE_GRID_APPLICATION optional_strings ';' +{ + if($2.empty()) + { + parser->invalidCommand("invalid command `application'"); + } + else + { + parser->invalidCommand("invalid command: `application " + $2.front() + "'"); + } +} +| ICE_GRID_SERVER optional_strings ';' +{ + if($2.empty()) + { + parser->invalidCommand("invalid command `server'"); + } + else + { + parser->invalidCommand("invalid command: `server " + $2.front() + "'"); + } +} +| ICE_GRID_NODE optional_strings ';' +{ + if($2.empty()) + { + parser->invalidCommand("invalid command `node'"); + } + else + { + parser->invalidCommand("invalid command: `node " + $2.front() + "'"); + } +} +| ICE_GRID_SERVICE optional_strings ';' +{ + if($2.empty()) + { + parser->invalidCommand("invalid command `service'"); + } + else + { + parser->invalidCommand("invalid command: `service " + $2.front() + "'"); + } +} +| ICE_GRID_OBJECT optional_strings ';' +{ + if($2.empty()) + { + parser->invalidCommand("invalid command `object'"); + } + else + { + parser->invalidCommand("invalid command: `object " + $2.front() + "'"); + } +} +| ICE_GRID_ADAPTER optional_strings ';' +{ + if($2.empty()) + { + parser->invalidCommand("invalid command `adapter'"); + } + else + { + parser->invalidCommand("invalid command: `adapter " + $2.front() + "'"); + } +} +| strings ';' +{ + parser->invalidCommand("invalid command `" + $1.front() + "'"); +} | error ';' { yyerrok; diff --git a/cpp/src/IceGrid/Parser.cpp b/cpp/src/IceGrid/Parser.cpp index ff6c5c5e347..2cf817d3c2a 100644 --- a/cpp/src/IceGrid/Parser.cpp +++ b/cpp/src/IceGrid/Parser.cpp @@ -153,7 +153,7 @@ Parser::addApplication(const list<string>& origArgs) if(args.size() < 1) { - error("`application add' requires at least one argument\n(`help' for more info)"); + invalidCommand("`application add' requires at least one argument"); return; } @@ -212,7 +212,7 @@ Parser::removeApplication(const list<string>& args) { if(args.size() != 1) { - error("`application remove' requires exactly one argument\n(`help' for more info)"); + invalidCommand("`application remove' requires exactly one argument"); return; } @@ -235,7 +235,7 @@ Parser::describeApplication(const list<string>& args) { if(args.size() < 1) { - error("`application describe' requires at least one argument\n(`help' for more info)"); + invalidCommand("`application describe' requires at least one argument"); return; } @@ -261,7 +261,7 @@ Parser::diffApplication(const list<string>& args) { if(args.size() < 1) { - error("`application diff' requires at least one argument\n(`help' for more info)"); + invalidCommand("`application diff' requires at least one argument"); return; } @@ -307,7 +307,7 @@ Parser::updateApplication(const list<string>& args) { if(args.size() < 1) { - error("`application diff' requires at least one argument\n(`help' for more info)"); + invalidCommand("`application diff' requires at least one argument"); return; } @@ -365,7 +365,7 @@ Parser::patchApplication(const list<string>& origArgs) if(args.size() != 1) { - error("`application patch' requires exactly one argument\n(`help' for more info)"); + invalidCommand("`application patch' requires exactly one argument"); return; } @@ -400,7 +400,7 @@ Parser::describeServerTemplate(const list<string>& args) { if(args.size() != 2) { - error("`server template describe' requires exactly two arguments\n(`help' for more info)"); + invalidCommand("`server template describe' requires exactly two arguments"); return; } @@ -451,7 +451,7 @@ Parser::instantiateServerTemplate(const list<string>& args) { if(args.size() < 3) { - error("`server template instantiate' requires at least three arguments\n(`help' for more info)"); + invalidCommand("`server template instantiate' requires at least three arguments"); return; } @@ -488,7 +488,7 @@ Parser::describeServiceTemplate(const list<string>& args) { if(args.size() != 2) { - error("`service template describe' requires exactly two arguments\n(`help' for more info)"); + invalidCommand("`service template describe' requires exactly two arguments"); return; } @@ -527,7 +527,7 @@ Parser::describeServiceTemplate(const list<string>& args) } else { - error("no service template with id `" + templ + "'"); + invalidCommand("no service template with id `" + templ + "'"); } } catch(const Ice::Exception& ex) @@ -541,7 +541,7 @@ Parser::describeNode(const list<string>& args) { if(args.size() != 1) { - error("`node describe' requires exactly one argument\n(`help' for more info)"); + invalidCommand("`node describe' requires exactly one argument"); return; } @@ -571,7 +571,7 @@ Parser::pingNode(const list<string>& args) { if(args.size() != 1) { - error("`node ping' requires exactly one argument\n(`help' for more info)"); + invalidCommand("`node ping' requires exactly one argument"); return; } @@ -597,7 +597,7 @@ Parser::printLoadNode(const list<string>& args) { if(args.size() != 1) { - error("`node load' requires exactly one argument\n(`help' for more info)"); + invalidCommand("`node load' requires exactly one argument"); return; } @@ -617,7 +617,7 @@ Parser::shutdownNode(const list<string>& args) { if(args.size() != 1) { - error("`node shutdown' requires exactly one argument\n(`help' for more info)"); + invalidCommand("`node shutdown' requires exactly one argument"); return; } @@ -650,7 +650,7 @@ Parser::removeServer(const list<string>& args) { if(args.size() != 1) { - error("`server start' requires exactly one argument\n(`help' for more info)"); + invalidCommand("`server start' requires exactly one argument"); return; } @@ -676,7 +676,7 @@ Parser::startServer(const list<string>& args) { if(args.size() != 1) { - error("`server start' requires exactly one argument\n(`help' for more info)"); + invalidCommand("`server start' requires exactly one argument"); return; } @@ -699,7 +699,7 @@ Parser::stopServer(const list<string>& args) { if(args.size() != 1) { - error("`server stop' requires exactly one argument\n(`help' for more info)"); + invalidCommand("`server stop' requires exactly one argument"); return; } @@ -738,7 +738,7 @@ Parser::patchServer(const list<string>& origArgs) if(args.size() != 1) { - error("`server patch' requires exactly one argument\n(`help' for more info)"); + invalidCommand("`server patch' requires exactly one argument"); return; } @@ -757,7 +757,7 @@ Parser::signalServer(const list<string>& args) { if(args.size() != 2) { - error("`server signal' requires exactly two arguments\n(`help' for more info)"); + invalidCommand("`server signal' requires exactly two arguments"); return; } @@ -779,7 +779,7 @@ Parser::writeMessage(const list<string>& args, int fd) { if(args.size() != 2) { - error("`server stdout or server stderr' requires exactly two arguments\n(`help' for more info)"); + invalidCommand("`server stdout or server stderr' requires exactly two arguments"); return; } @@ -800,7 +800,7 @@ Parser::describeServer(const list<string>& args) { if(args.size() != 1) { - error("`server describe' requires exactly one argument\n(`help' for more info)"); + invalidCommand("`server describe' requires exactly one argument"); return; } @@ -830,7 +830,7 @@ Parser::stateServer(const list<string>& args) { if(args.size() != 1) { - error("`server state' requires exactly one argument\n(`help' for more info)"); + invalidCommand("`server state' requires exactly one argument"); return; } @@ -881,7 +881,7 @@ Parser::pidServer(const list<string>& args) { if(args.size() != 1) { - error("`server pid' requires exactly one argument\n(`help' for more info)"); + invalidCommand("`server pid' requires exactly one argument"); return; } @@ -902,11 +902,11 @@ Parser::enableServer(const list<string>& args, bool enable) { if(enable) { - error("`server enable' requires exactly one argument\n(`help' for more info)"); + invalidCommand("`server enable' requires exactly one argument"); } else { - error("`server disable' requires exactly one argument\n(`help' for more info)"); + invalidCommand("`server disable' requires exactly one argument"); } return; } @@ -940,7 +940,7 @@ Parser::endpointsAdapter(const list<string>& args) { if(args.size() != 1) { - error("`adapter endpoints' requires exactly one argument\n(`help' for more info)"); + invalidCommand("`adapter endpoints' requires exactly one argument"); return; } @@ -975,7 +975,7 @@ Parser::removeAdapter(const list<string>& args) { if(args.size() != 1) { - error("`adapter remove' requires exactly one argument\n(`help' for more info)"); + invalidCommand("`adapter remove' requires exactly one argument"); return; } @@ -1008,7 +1008,7 @@ Parser::addObject(const list<string>& args) { if(args.size() < 1) { - error("`object add' requires at least one argument\n(`help' for more info)"); + invalidCommand("`object add' requires at least one argument"); return; } @@ -1039,7 +1039,7 @@ Parser::removeObject(const list<string>& args) { if(args.size() != 1) { - error("`object remove' requires exactly one argument\n(`help' for more info)"); + invalidCommand("`object remove' requires exactly one argument"); return; } @@ -1058,7 +1058,7 @@ Parser::findObject(const list<string>& args) { if(args.size() != 1) { - error("`object find' requires exactly one argument\n(`help' for more info)"); + invalidCommand("`object find' requires exactly one argument"); return; } @@ -1363,6 +1363,18 @@ Parser::scanPosition(const char* s) } void +Parser::invalidCommand(const char* s) +{ + error(string(s) + "\n(`help' for more info)"); +} + +void +Parser::invalidCommand(const string& s) +{ + invalidCommand(s.c_str()); +} + +void Parser::error(const char* s) { if(_commands.empty() && !isatty(fileno(yyin))) diff --git a/cpp/src/IceGrid/Parser.h b/cpp/src/IceGrid/Parser.h index a479b249351..e86e71af128 100644 --- a/cpp/src/IceGrid/Parser.h +++ b/cpp/src/IceGrid/Parser.h @@ -122,6 +122,9 @@ public: const char* getPrompt(); void scanPosition(const char*); + void invalidCommand(const char*); + void invalidCommand(const std::string&); + void error(const char*); void error(const std::string&); |