diff --git a/ChangeLog b/ChangeLog index 7d10b297..bfaf36e1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2009-05-12 Tatsuhiro Tsujikawa + + 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 Selecting files are now done in diff --git a/src/OptionHandlerException.cc b/src/OptionHandlerException.cc index 70f5b0c3..e8c5d504 100644 --- a/src/OptionHandlerException.cc +++ b/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() {} diff --git a/src/OptionHandlerException.h b/src/OptionHandlerException.h index 2304fe0f..046e5413 100644 --- a/src/OptionHandlerException.h +++ b/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; diff --git a/src/OptionHandlerImpl.h b/src/OptionHandlerImpl.h index 3b9d4046..1a7f6954 100644 --- a/src/OptionHandlerImpl.h +++ b/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")); } } diff --git a/src/OptionParser.cc b/src/OptionParser.cc index 42920737..dd754ae5 100644 --- a/src/OptionParser.cc +++ b/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) { diff --git a/src/OptionParser.h b/src/OptionParser.h index 32422f50..3cdfe919 100644 --- a/src/OptionParser.h +++ b/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& nonopts, int argc, char* const argv[]); diff --git a/src/PStringSegment.cc b/src/PStringSegment.cc index b2c9206a..b550d618 100644 --- a/src/PStringSegment.cc +++ b/src/PStringSegment.cc @@ -33,7 +33,6 @@ */ /* copyright --> */ #include "PStringSegment.h" -#include "FatalException.h" #include "PStringVisitor.h" namespace aria2 { diff --git a/src/ParameterizedStringParser.cc b/src/ParameterizedStringParser.cc index db69a9c3..0c717ea9 100644 --- a/src/ParameterizedStringParser.cc +++ b/src/ParameterizedStringParser.cc @@ -33,7 +33,10 @@ */ /* copyright --> */ #include "ParameterizedStringParser.h" -#include "FatalException.h" + +#include + +#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 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 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 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)); diff --git a/src/download_helper.cc b/src/download_helper.cc index b12c90a3..52026994 100644 --- a/src/download_helper.cc +++ b/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()); } diff --git a/test/ParameterizedStringParserTest.cc b/test/ParameterizedStringParserTest.cc index 88690d31..fd5104d0 100644 --- a/test/ParameterizedStringParserTest.cc +++ b/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 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 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 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 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 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 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."); } }