Browse Source

2009-05-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Throw DlAbortEx instead of FatalException during parsing options
	because we don't want for aria2 to quit when bad option is passed
	via XML-RPC.
	* src/OptionHandlerException.cc
	* src/OptionHandlerException.h
	* src/OptionHandlerImpl.h
	* src/OptionParser.cc
	* src/OptionParser.h
	* src/PStringSegment.cc
	* src/ParameterizedStringParser.cc
	* src/download_helper.cc
	* test/ParameterizedStringParserTest.cc
Tatsuhiro Tsujikawa 16 years ago
parent
commit
62165b9ed1

+ 15 - 0
ChangeLog

@@ -1,3 +1,18 @@
+2009-05-12  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Throw DlAbortEx instead of FatalException during parsing options
+	because we don't want for aria2 to quit when bad option is passed
+	via XML-RPC.
+	* src/OptionHandlerException.cc
+	* src/OptionHandlerException.h
+	* src/OptionHandlerImpl.h
+	* src/OptionParser.cc
+	* src/OptionParser.h
+	* src/PStringSegment.cc
+	* src/ParameterizedStringParser.cc
+	* src/download_helper.cc
+	* test/ParameterizedStringParserTest.cc
+
 2009-05-12  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Selecting files are now done in

+ 3 - 3
src/OptionHandlerException.cc

@@ -41,17 +41,17 @@ const std::string OptionHandlerException::MESSAGE
 ("Exception occurred while processing option %s:");
 
 OptionHandlerException::OptionHandlerException(const std::string& optName):
-  FatalException
+  RecoverableException
   (StringFormat(MESSAGE.c_str(), optName.c_str()).str()), _optName(optName) {}
 
 OptionHandlerException::OptionHandlerException(const std::string& optName,
 					       const Exception& cause):
-  FatalException
+  RecoverableException
   (StringFormat(MESSAGE.c_str(), optName.c_str()).str(), cause),
   _optName(optName) {}
 
 OptionHandlerException::OptionHandlerException(const OptionHandlerException& e):
-  FatalException(e), _optName(e._optName) {}
+  RecoverableException(e), _optName(e._optName) {}
 
 OptionHandlerException::~OptionHandlerException() throw() {}
 

+ 2 - 2
src/OptionHandlerException.h

@@ -34,11 +34,11 @@
 /* copyright --> */
 #ifndef _D_OPTION_HANDLER_EXCEPTION_H_
 #define _D_OPTION_HANDLER_EXCEPTION_H_
-#include "FatalException.h"
+#include "RecoverableException.h"
 
 namespace aria2 {
 
-class OptionHandlerException:public FatalException {
+class OptionHandlerException:public RecoverableException {
 private:
   std::string _optName;
 

+ 8 - 8
src/OptionHandlerImpl.h

@@ -46,7 +46,7 @@
 
 #include "NameMatchOptionHandler.h"
 #include "Util.h"
-#include "FatalException.h"
+#include "DlAbortEx.h"
 #include "prefs.h"
 #include "Option.h"
 #include "StringFormat.h"
@@ -127,7 +127,7 @@ public:
       option.put(_optName, V_FALSE);
     } else {
       std::string msg = _optName+" "+_("must be either 'true' or 'false'.");
-      throw FatalException(msg);
+      throw DlAbortEx(msg);
     }
   }
 
@@ -160,7 +160,7 @@ public:
       int32_t v = seq.next();
       if(v < _min || _max < v) {
 	std::string msg = _optName+" "+_("must be between %s and %s.");
-	throw FatalException
+	throw DlAbortEx
 	  (StringFormat(msg.c_str(), Util::itos(_min).c_str(),
 			Util::itos(_max).c_str()).str());
       }
@@ -215,7 +215,7 @@ public:
       } else {
 	msg += _("must be a number.");
       }
-      throw FatalException(msg);
+      throw DlAbortEx(msg);
     }
   }
 
@@ -281,7 +281,7 @@ public:
       } else {
 	msg += _("must be a number.");
       }
-      throw FatalException(msg);
+      throw DlAbortEx(msg);
     }
   }
 
@@ -462,7 +462,7 @@ public:
 	  msg += "'"+*itr+"' ";
 	}
       }
-      throw FatalException(msg);
+      throw DlAbortEx(msg);
     } else {
       option.put(_optName, optarg);
     }
@@ -502,7 +502,7 @@ public:
     int32_t port = Util::parseInt(proxy.second);
     if(proxy.first.empty() || proxy.second.empty() ||
        port <= 0 || 65535 < port) {
-      throw FatalException(_("unrecognized proxy format"));
+      throw DlAbortEx(_("unrecognized proxy format"));
     }
     option.put(_optName, optarg);
     setHostAndPort(option, proxy.first, port);
@@ -545,7 +545,7 @@ public:
     if(req.setUrl(url)) {
       option.put(_optName, url);
     } else {
-      throw FatalException(_("unrecognized proxy format"));
+      throw DlAbortEx(_("unrecognized proxy format"));
     }
   }
 

+ 1 - 1
src/OptionParser.cc

@@ -142,7 +142,7 @@ void OptionParser::parseArg
       op = findByShortName(c);
     }
     if(op.isNull()) {
-      throw FatalException("Failed to parse command-line options.");
+      throw DlAbortEx("Failed to parse command-line options.");
     }
     out << op->getName() << "=";
     if(optarg) {

+ 1 - 1
src/OptionParser.h

@@ -65,7 +65,7 @@ public:
 
   // Parses options in argv and writes option name and value to out in
   // NAME=VALUE format. Non-option strings are stored in nonopts.
-  // Throws FatalException when an unrecognized option is found.
+  // Throws Exception when an unrecognized option is found.
   void parseArg(std::ostream& out, std::deque<std::string>& nonopts,
 		int argc, char* const argv[]);
 

+ 0 - 1
src/PStringSegment.cc

@@ -33,7 +33,6 @@
  */
 /* copyright --> */
 #include "PStringSegment.h"
-#include "FatalException.h"
 #include "PStringVisitor.h"
 
 namespace aria2 {

+ 10 - 8
src/ParameterizedStringParser.cc

@@ -33,7 +33,10 @@
  */
 /* copyright --> */
 #include "ParameterizedStringParser.h"
-#include "FatalException.h"
+
+#include <utility>
+
+#include "DlAbortEx.h"
 #include "Util.h"
 #include "PStringSegment.h"
 #include "PStringSelect.h"
@@ -41,7 +44,6 @@
 #include "NumberDecorator.h"
 #include "FixedWidthNumberDecorator.h"
 #include "AlphaNumberDecorator.h"
-#include <utility>
 
 namespace aria2 {
 
@@ -86,12 +88,12 @@ PStringDatumHandle ParameterizedStringParser::createSelect(const std::string& sr
   ++offset;
   std::string::size_type rightParenIndex = src.find("}", offset);
   if(rightParenIndex == std::string::npos) {
-    throw FatalException("Missing '}' in the parameterized string.");
+    throw DlAbortEx("Missing '}' in the parameterized string.");
   }
   std::deque<std::string> values;
   Util::slice(values, src.substr(offset, rightParenIndex-offset), ',', true);
   if(values.empty()) {
-    throw FatalException("Empty {} is not allowed.");
+    throw DlAbortEx("Empty {} is not allowed.");
   }
   offset = rightParenIndex+1;
   PStringDatumHandle next = diggPString(src, offset);
@@ -104,7 +106,7 @@ PStringDatumHandle ParameterizedStringParser::createLoop(const std::string& src,
   ++offset;
   std::string::size_type rightParenIndex = src.find("]", offset);
   if(rightParenIndex == std::string::npos) {
-    throw FatalException("Missing ']' in the parameterized string.");
+    throw DlAbortEx("Missing ']' in the parameterized string.");
   }
   std::string loopStr = src.substr(offset, rightParenIndex-offset);
   offset = rightParenIndex+1;
@@ -116,13 +118,13 @@ PStringDatumHandle ParameterizedStringParser::createLoop(const std::string& src,
     if(Util::isNumber(stepStr)) {
       step = Util::parseUInt(stepStr);
     } else {
-      throw FatalException("A step count must be a positive number.");
+      throw DlAbortEx("A step count must be a positive number.");
     }
     loopStr.erase(colonIndex);
   }
   std::pair<std::string, std::string> range = Util::split(loopStr, "-");
   if(range.first.empty() || range.second.empty()) {
-    throw FatalException("Loop range missing.");
+    throw DlAbortEx("Loop range missing.");
   }
   NumberDecoratorHandle nd;
   unsigned int start;
@@ -140,7 +142,7 @@ PStringDatumHandle ParameterizedStringParser::createLoop(const std::string& src,
     start = Util::alphaToNum(range.first);
     end = Util::alphaToNum(range.second);
   } else {
-    throw FatalException("Invalid loop range.");
+    throw DlAbortEx("Invalid loop range.");
   }
 
   PStringDatumHandle next(diggPString(src, offset));

+ 3 - 3
src/download_helper.cc

@@ -50,7 +50,7 @@
 #include "UriListParser.h"
 #include "SingleFileDownloadContext.h"
 #include "RecoverableException.h"
-#include "FatalException.h"
+#include "DlAbortEx.h"
 #include "message.h"
 #include "StringFormat.h"
 #include "DefaultBtContext.h"
@@ -258,7 +258,7 @@ void createRequestGroupForMetalink
 				   option->get(PREF_METALINK_FILE),
 				   option);
   if(result.empty()) {
-    throw FatalException(MSG_NO_FILES_TO_DOWNLOAD);
+    throw DlAbortEx(MSG_NO_FILES_TO_DOWNLOAD);
   }
 }
 #endif // ENABLE_METALINK
@@ -397,7 +397,7 @@ void createRequestGroupForUriList
     createRequestGroupForUriList(result, option, std::cin);
   } else {
     if(!File(option->get(PREF_INPUT_FILE)).isFile()) {
-      throw FatalException
+      throw DlAbortEx
 	(StringFormat(EX_FILE_OPEN, option->get(PREF_INPUT_FILE).c_str(),
 		      "No such file").str());
     }

+ 11 - 11
test/ParameterizedStringParserTest.cc

@@ -8,7 +8,7 @@
 #include "PStringSelect.h"
 #include "PStringSegment.h"
 #include "PStringNumLoop.h"
-#include "FatalException.h"
+#include "DlAbortEx.h"
 
 namespace aria2 {
 
@@ -74,7 +74,7 @@ void ParameterizedStringParserTest::testParse_select_empty()
   try {
     SharedHandle<PStringDatum> ls = ParameterizedStringParser().parse("{}");
     CPPUNIT_FAIL("exception must be thrown.");
-  } catch(FatalException& e) {
+  } catch(DlAbortEx& e) {
     std::cerr << e.stackTrace() << std::endl;
   } catch(...) {
     CPPUNIT_FAIL("unexpected exception thrown.");
@@ -86,7 +86,7 @@ void ParameterizedStringParserTest::testParse_select_missingParen()
   try {
     SharedHandle<PStringDatum> ls = ParameterizedStringParser().parse("{alpha");
     CPPUNIT_FAIL("exception must be thrown.");
-  } catch(FatalException& e) {
+  } catch(DlAbortEx& e) {
     std::cerr << e.stackTrace() << std::endl;
   } catch(...) {
     CPPUNIT_FAIL("unexpected exception was thrown.");
@@ -141,7 +141,7 @@ void ParameterizedStringParserTest::testParse_loop_empty()
   try {
     SharedHandle<PStringDatum> ls = ParameterizedStringParser().parse("[]");
     CPPUNIT_FAIL("exception must be thrown.");
-  } catch(FatalException& e) {
+  } catch(DlAbortEx& e) {
     std::cerr << e.stackTrace() << std::endl;
   } catch(...) {
     CPPUNIT_FAIL("unexpected exception was thrown.");
@@ -153,7 +153,7 @@ void ParameterizedStringParserTest::testParse_loop_missingParen()
   try {
     SharedHandle<PStringDatum> ls = ParameterizedStringParser().parse("[");
     CPPUNIT_FAIL("exception must be thrown.");
-  } catch(FatalException& e) {
+  } catch(DlAbortEx& e) {
     std::cerr << e.stackTrace() << std::endl;
   } catch(...) {
     CPPUNIT_FAIL("unexpected exception was thrown.");
@@ -165,7 +165,7 @@ void ParameterizedStringParserTest::testParse_loop_missingStep()
   try {
     SharedHandle<PStringDatum> ls = ParameterizedStringParser().parse("[1-10:]");
     CPPUNIT_FAIL("exception must be thrown.");
-  } catch(FatalException& e) {
+  } catch(DlAbortEx& e) {
     std::cerr << e.stackTrace() << std::endl;
   } catch(...) {
     CPPUNIT_FAIL("unexpected exception was thrown.");
@@ -177,7 +177,7 @@ void ParameterizedStringParserTest::testParse_loop_missingRange()
   try {
     SharedHandle<PStringDatum> ls = ParameterizedStringParser().parse("[1-]");
     CPPUNIT_FAIL("exception must be thrown.");
-  } catch(FatalException& e) {
+  } catch(DlAbortEx& e) {
     std::cerr << e.stackTrace() << std::endl;
   } catch(...) {
     CPPUNIT_FAIL("unexpected exception was thrown.");
@@ -200,10 +200,10 @@ void ParameterizedStringParserTest::testParse_loop_mixedChar()
   try {
     ParameterizedStringParser().parse("[1-z:2]");
     CPPUNIT_FAIL("exception must be thrown.");
-  } catch(FatalException& e) {
+  } catch(DlAbortEx& e) {
     std::cerr << e.stackTrace() << std::endl;
   } catch(...) {
-    CPPUNIT_FAIL("FatalException must be thrown.");
+    CPPUNIT_FAIL("DlAbortEx must be thrown.");
   }
 }
 
@@ -212,10 +212,10 @@ void ParameterizedStringParserTest::testParse_loop_mixedCase()
   try {
     ParameterizedStringParser().parse("[a-Z:2]");
     CPPUNIT_FAIL("exception must be thrown.");
-  } catch(FatalException& e) {
+  } catch(DlAbortEx& e) {
     std::cerr << e.stackTrace() << std::endl;
   } catch(...) {
-    CPPUNIT_FAIL("FatalException must be thrown.");
+    CPPUNIT_FAIL("DlAbortEx must be thrown.");
   }
 }