mirror of https://github.com/aria2/aria2
Moved errorCode_ from RecoverableException to Exception and added errorCode to
stackTrace. Also changed errno to errNum in stackTrace.pull/1/head
parent
45fde1adaf
commit
476ba70a9f
|
@ -262,9 +262,9 @@ bool AbstractCommand::execute() {
|
||||||
req_->getUri().c_str()),
|
req_->getUri().c_str()),
|
||||||
DL_ABORT_EX2(fmt("URI=%s", req_->getCurrentUri().c_str()),
|
DL_ABORT_EX2(fmt("URI=%s", req_->getCurrentUri().c_str()),
|
||||||
err));
|
err));
|
||||||
fileEntry_->addURIResult(req_->getUri(), err.getCode());
|
fileEntry_->addURIResult(req_->getUri(), err.getErrorCode());
|
||||||
requestGroup_->setLastErrorCode(err.getCode());
|
requestGroup_->setLastErrorCode(err.getErrorCode());
|
||||||
if(err.getCode() == error_code::CANNOT_RESUME) {
|
if(err.getErrorCode() == error_code::CANNOT_RESUME) {
|
||||||
requestGroup_->increaseResumeFailureCount();
|
requestGroup_->increaseResumeFailureCount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -290,9 +290,9 @@ bool AbstractCommand::execute() {
|
||||||
getCuid(),
|
getCuid(),
|
||||||
req_->getUri().c_str()),
|
req_->getUri().c_str()),
|
||||||
err);
|
err);
|
||||||
fileEntry_->addURIResult(req_->getUri(), err.getCode());
|
fileEntry_->addURIResult(req_->getUri(), err.getErrorCode());
|
||||||
requestGroup_->setLastErrorCode(err.getCode());
|
requestGroup_->setLastErrorCode(err.getErrorCode());
|
||||||
if(err.getCode() == error_code::CANNOT_RESUME) {
|
if(err.getErrorCode() == error_code::CANNOT_RESUME) {
|
||||||
requestGroup_->increaseResumeFailureCount();
|
requestGroup_->increaseResumeFailureCount();
|
||||||
}
|
}
|
||||||
onAbort();
|
onAbort();
|
||||||
|
@ -304,8 +304,8 @@ bool AbstractCommand::execute() {
|
||||||
} catch(DownloadFailureException& err) {
|
} catch(DownloadFailureException& err) {
|
||||||
A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, err);
|
A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, err);
|
||||||
if(req_) {
|
if(req_) {
|
||||||
fileEntry_->addURIResult(req_->getUri(), err.getCode());
|
fileEntry_->addURIResult(req_->getUri(), err.getErrorCode());
|
||||||
requestGroup_->setLastErrorCode(err.getCode());
|
requestGroup_->setLastErrorCode(err.getErrorCode());
|
||||||
}
|
}
|
||||||
requestGroup_->setHaltRequested(true);
|
requestGroup_->setHaltRequested(true);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -45,7 +45,8 @@ Exception::Exception
|
||||||
: file_(file),
|
: file_(file),
|
||||||
line_(line),
|
line_(line),
|
||||||
errNum_(0),
|
errNum_(0),
|
||||||
msg_(msg)
|
msg_(msg),
|
||||||
|
errorCode_(error_code::UNKNOWN_ERROR)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Exception::Exception
|
Exception::Exception
|
||||||
|
@ -57,7 +58,20 @@ Exception::Exception
|
||||||
line_(line),
|
line_(line),
|
||||||
errNum_(0),
|
errNum_(0),
|
||||||
msg_(msg),
|
msg_(msg),
|
||||||
cause_(cause.copy())
|
cause_(cause.copy()),
|
||||||
|
errorCode_(cause.errorCode_)
|
||||||
|
{}
|
||||||
|
|
||||||
|
Exception::Exception
|
||||||
|
(const char* file,
|
||||||
|
int line,
|
||||||
|
const std::string& msg,
|
||||||
|
error_code::Value errorCode)
|
||||||
|
: file_(file),
|
||||||
|
line_(line),
|
||||||
|
errNum_(0),
|
||||||
|
msg_(msg),
|
||||||
|
errorCode_(errorCode)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Exception::Exception
|
Exception::Exception
|
||||||
|
@ -68,7 +82,8 @@ Exception::Exception
|
||||||
: file_(file),
|
: file_(file),
|
||||||
line_(line),
|
line_(line),
|
||||||
errNum_(errNum),
|
errNum_(errNum),
|
||||||
msg_(msg)
|
msg_(msg),
|
||||||
|
errorCode_(error_code::UNKNOWN_ERROR)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Exception::~Exception() throw() {}
|
Exception::~Exception() throw() {}
|
||||||
|
@ -78,13 +93,17 @@ std::string Exception::stackTrace() const
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
s << "Exception: " << "[" << file_ << ":" << line_ << "] ";
|
s << "Exception: " << "[" << file_ << ":" << line_ << "] ";
|
||||||
if(errNum_) {
|
if(errNum_) {
|
||||||
s << "errno=" << errNum_ << " ";
|
s << "errNum=" << errNum_ << " ";
|
||||||
}
|
}
|
||||||
|
s << "errorCode=" << errorCode_ << " ";
|
||||||
s << what() << "\n";
|
s << what() << "\n";
|
||||||
SharedHandle<Exception> e = cause_;
|
SharedHandle<Exception> e = cause_;
|
||||||
while(e) {
|
while(e) {
|
||||||
s << " -> " << "[" << e->file_ << ":" << e->line_ << "] "
|
s << " -> " << "[" << e->file_ << ":" << e->line_ << "] ";
|
||||||
<< e->what() << "\n";
|
if(e->getErrNum()) {
|
||||||
|
s << "errNum=" << e->getErrNum() << " ";
|
||||||
|
}
|
||||||
|
s << "errorCode=" << e->getErrorCode() << " " << e->what() << "\n";
|
||||||
e = e->cause_;
|
e = e->cause_;
|
||||||
}
|
}
|
||||||
return s.str();
|
return s.str();
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "SharedHandle.h"
|
#include "SharedHandle.h"
|
||||||
|
#include "error_code.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -49,21 +50,27 @@ private:
|
||||||
const char* file_;
|
const char* file_;
|
||||||
|
|
||||||
int line_;
|
int line_;
|
||||||
|
// This is low-level system error code, typically errno in Linux.
|
||||||
int errNum_;
|
int errNum_;
|
||||||
|
|
||||||
std::string msg_;
|
std::string msg_;
|
||||||
|
// Exception that this object wraps. Normally this cause_ is the
|
||||||
|
// root cause of this exception.
|
||||||
SharedHandle<Exception> cause_;
|
SharedHandle<Exception> cause_;
|
||||||
|
// This is application-level error code.
|
||||||
|
error_code::Value errorCode_;
|
||||||
protected:
|
protected:
|
||||||
virtual SharedHandle<Exception> copy() const = 0;
|
virtual SharedHandle<Exception> copy() const = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Exception(const char* file, int line, const std::string& msg);
|
Exception(const char* file, int line, const std::string& msg);
|
||||||
|
// errorCode_ is initializedwith cause.errorCode_.
|
||||||
Exception(const char* file, int line, const std::string& msg,
|
Exception(const char* file, int line, const std::string& msg,
|
||||||
const Exception& cause);
|
const Exception& cause);
|
||||||
|
|
||||||
|
Exception(const char* file, int line, const std::string& msg,
|
||||||
|
error_code::Value errorCode);
|
||||||
|
|
||||||
Exception(const char* file, int line, int errNum, const std::string& msg);
|
Exception(const char* file, int line, int errNum, const std::string& msg);
|
||||||
|
|
||||||
virtual ~Exception() throw();
|
virtual ~Exception() throw();
|
||||||
|
@ -76,6 +83,11 @@ public:
|
||||||
{
|
{
|
||||||
return errNum_;
|
return errNum_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error_code::Value getErrorCode() const
|
||||||
|
{
|
||||||
|
return errorCode_;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -43,24 +43,25 @@ SharedHandle<Exception> RecoverableException::copy() const
|
||||||
}
|
}
|
||||||
|
|
||||||
RecoverableException::RecoverableException
|
RecoverableException::RecoverableException
|
||||||
(const char* file, int line, const std::string& msg):
|
(const char* file, int line, const std::string& msg)
|
||||||
Exception(file, line, msg),
|
: Exception(file, line, msg)
|
||||||
code_(error_code::UNKNOWN_ERROR) {}
|
{}
|
||||||
|
|
||||||
RecoverableException::RecoverableException
|
RecoverableException::RecoverableException
|
||||||
(const char* file, int line, const std::string& msg,
|
(const char* file, int line, const std::string& msg,
|
||||||
const Exception& cause):
|
const Exception& cause)
|
||||||
Exception(file, line, msg, cause),
|
: Exception(file, line, msg, cause)
|
||||||
code_(error_code::UNKNOWN_ERROR) {}
|
{}
|
||||||
|
|
||||||
RecoverableException::RecoverableException
|
|
||||||
(const char* file, int line, int errNum, const std::string& msg):
|
|
||||||
Exception(file, line, errNum, msg),
|
|
||||||
code_(error_code::UNKNOWN_ERROR) {}
|
|
||||||
|
|
||||||
RecoverableException::RecoverableException
|
RecoverableException::RecoverableException
|
||||||
(const char* file, int line, const std::string& msg,
|
(const char* file, int line, const std::string& msg,
|
||||||
error_code::Value result):
|
error_code::Value errorCode)
|
||||||
Exception(file, line, msg), code_(result) {}
|
: Exception(file, line, msg, errorCode)
|
||||||
|
{}
|
||||||
|
|
||||||
|
RecoverableException::RecoverableException
|
||||||
|
(const char* file, int line, int errNum, const std::string& msg)
|
||||||
|
: Exception(file, line, errNum, msg)
|
||||||
|
{}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -35,14 +35,10 @@
|
||||||
#ifndef D_RECOVERABLE_EXCEPTION_H
|
#ifndef D_RECOVERABLE_EXCEPTION_H
|
||||||
#define D_RECOVERABLE_EXCEPTION_H
|
#define D_RECOVERABLE_EXCEPTION_H
|
||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
#include "error_code.h"
|
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class RecoverableException:public Exception {
|
class RecoverableException:public Exception {
|
||||||
private:
|
|
||||||
error_code::Value code_;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual SharedHandle<Exception> copy() const;
|
virtual SharedHandle<Exception> copy() const;
|
||||||
public:
|
public:
|
||||||
|
@ -51,13 +47,11 @@ public:
|
||||||
RecoverableException(const char* file, int line, const std::string& msg,
|
RecoverableException(const char* file, int line, const std::string& msg,
|
||||||
const Exception& cause);
|
const Exception& cause);
|
||||||
|
|
||||||
|
RecoverableException(const char* file, int line, const std::string& msg,
|
||||||
|
error_code::Value errorCode);
|
||||||
|
|
||||||
RecoverableException
|
RecoverableException
|
||||||
(const char* file, int line, int errNum, const std::string& msg);
|
(const char* file, int line, int errNum, const std::string& msg);
|
||||||
|
|
||||||
RecoverableException(const char* file, int line, const std::string& msg,
|
|
||||||
error_code::Value result);
|
|
||||||
|
|
||||||
error_code::Value getCode() const { return code_; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -25,15 +25,17 @@ CPPUNIT_TEST_SUITE_REGISTRATION(ExceptionTest);
|
||||||
|
|
||||||
void ExceptionTest::testStackTrace()
|
void ExceptionTest::testStackTrace()
|
||||||
{
|
{
|
||||||
DownloadFailureException c1 = DOWNLOAD_FAILURE_EXCEPTION("cause1");
|
DownloadFailureException c1 = DOWNLOAD_FAILURE_EXCEPTION2
|
||||||
|
("cause1", error_code::TIME_OUT);
|
||||||
DownloadFailureException c2 = DOWNLOAD_FAILURE_EXCEPTION2("cause2", c1);
|
DownloadFailureException c2 = DOWNLOAD_FAILURE_EXCEPTION2("cause2", c1);
|
||||||
DownloadFailureException e = DOWNLOAD_FAILURE_EXCEPTION2("exception thrown",
|
DownloadFailureException e = DOWNLOAD_FAILURE_EXCEPTION2("exception thrown",
|
||||||
c2);
|
c2);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL
|
CPPUNIT_ASSERT_EQUAL
|
||||||
(std::string("Exception: [ExceptionTest.cc:31] exception thrown\n"
|
(std::string
|
||||||
" -> [ExceptionTest.cc:29] cause2\n"
|
("Exception: [ExceptionTest.cc:32] errorCode=2 exception thrown\n"
|
||||||
" -> [ExceptionTest.cc:28] cause1\n"),
|
" -> [ExceptionTest.cc:30] errorCode=2 cause2\n"
|
||||||
|
" -> [ExceptionTest.cc:29] errorCode=2 cause1\n"),
|
||||||
e.stackTrace());
|
e.stackTrace());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue