Commit c8289901 authored by David COME's avatar David COME
Browse files

Removed the castor::tape::Exception class

parent 9744b1ea
......@@ -21,7 +21,7 @@
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#define _XOPEN_SOURCE 600
// Local Files
#include "Exception.hpp"
......@@ -45,6 +45,7 @@ castor::exception::Exception::Exception(
std::exception() {
m_serrno = rhs.m_serrno;
m_message << rhs.m_message.str();
m_backtrace = rhs.m_backtrace;
}
......@@ -72,3 +73,9 @@ const char * castor::exception::Exception::what() const throw () {
// destructor
//------------------------------------------------------------------------------
castor::exception::Exception::~Exception() throw() {}
//------------------------------------------------------------------------------
// setWhat
//------------------------------------------------------------------------------
void castor::exception::Exception::setWhat(const std::string& what) {
getMessage() << what;
}
\ No newline at end of file
......@@ -126,6 +126,8 @@ namespace castor {
mutable std::string m_what;
protected:
void setWhat(const std::string &w);
/**
* Backtrace object. Its constructor does the heavy lifting of
* generating the backtrace.
......
......@@ -58,7 +58,7 @@ set (SERVER_LIB_SRC_FILES
)
add_library (castorserver SHARED ${SERVER_LIB_SRC_FILES})
CastorSetLibraryVersions (castorserver)
target_link_libraries (castorserver cap castorclient castorcommon Exception)
target_link_libraries (castorserver cap castorclient castorcommon)
install (TARGETS castorserver LIBRARY DESTINATION ${CASTOR_DEST_LIB_DIR}
NAMELINK_SKIP)
......
......@@ -77,7 +77,7 @@ void castor::server::ChildProcess::wait() {
/* Check child status*/
if (ret == m_pid) parseStatus(status);
if(!m_finished)
throw castor::tape::Exception("Process did not exit after waitpid().");
throw castor::exception::Exception("Process did not exit after waitpid().");
}
int castor::server::ChildProcess::exitCode() {
......
......@@ -23,7 +23,7 @@
#pragma once
#include "castor/exception/Errnum.hpp"
#include "castor/tape/tapeserver/exception/Exception.hpp"
#include "castor/exception/Exception.hpp"
#include <unistd.h>
......@@ -48,22 +48,22 @@ namespace server {
/**
* Exceptions for wrong usage.
*/
class ProcessStillRunning: public castor::tape::Exception {
class ProcessStillRunning: public castor::exception::Exception {
public:
ProcessStillRunning(const std::string & what = "Process still running"):
castor::tape::Exception::Exception(what) {}
castor::exception::Exception::Exception(what) {}
};
class ProcessNeverStarted: public castor::tape::Exception {
class ProcessNeverStarted: public castor::exception::Exception {
public:
ProcessNeverStarted(const std::string & what = "Process never started"):
castor::tape::Exception::Exception(what) {}
castor::exception::Exception::Exception(what) {}
};
class ProcessWasKilled: public castor::tape::Exception {
class ProcessWasKilled: public castor::exception::Exception {
public:
ProcessWasKilled(const std::string & what = "Process was killed"):
castor::tape::Exception::Exception(what) {}
castor::exception::Exception::Exception(what) {}
};
ChildProcess(): m_started(false), m_finished(false), m_exited(false),
......
#include "castor/server/Mutex.hpp"
#include "castor/exception/Errnum.hpp"
#include "castor/exception/Exception.hpp"
//------------------------------------------------------------------------------
//constructor
......
......@@ -25,8 +25,6 @@
#include <pthread.h>
#include <semaphore.h>
#include "castor/exception/Errnum.hpp"
#include "castor/tape/tapeserver/exception/Exception.hpp"
namespace castor {
namespace server {
......
......@@ -26,7 +26,7 @@
#include <pthread.h>
#include <semaphore.h>
#include "castor/exception/Errnum.hpp"
#include "castor/tape/tapeserver/exception/Exception.hpp"
#include "castor/exception/Exception.hpp"
#include "castor/server/Mutex.hpp"
namespace castor {
......@@ -37,9 +37,9 @@ namespace server {
/**
* An exception class thrown by the Thread class.
*/
class UncaughtExceptionInThread: public castor::tape::Exception {
class UncaughtExceptionInThread: public castor::exception::Exception {
public:
UncaughtExceptionInThread(const std::string& w= ""): castor::tape::Exception(w) {}
UncaughtExceptionInThread(const std::string& w= ""): castor::exception::Exception(w) {}
};
/**
......
......@@ -99,7 +99,7 @@ namespace threadedUnitTests {
private:
void run() {
throw castor::tape::Exception("Exception in child thread");
throw castor::exception::Exception("Exception in child thread");
}
};
......
......@@ -82,7 +82,7 @@ namespace unitTests {
class Thread_exception_throwing: public castor::server::Thread {
private:
void run() {
throw castor::tape::Exception("Exception in child thread");
throw castor::exception::Exception("Exception in child thread");
}
};
TEST(castor_tape_threading, Thread_exception_throwing) {
......
......@@ -39,7 +39,6 @@ add_subdirectory(client)
add_subdirectory(SCSI)
add_subdirectory(drive)
add_subdirectory(system)
add_subdirectory(exception)
add_subdirectory(utils)
add_subdirectory(file)
add_subdirectory(daemon)
......
......@@ -95,7 +95,7 @@ SCSI::DeviceInfo::DeviceFile SCSI::DeviceVector::readDeviceFile(std::string path
DeviceInfo::DeviceFile ret;
std::string file = readfile(path);
if (!::sscanf(file.c_str(), "%d:%d\n", &ret.major, &ret.minor))
throw Exception(std::string("Could not parse file: ") + path);
throw castor::exception::Exception(std::string("Could not parse file: ") + path);
return ret;
}
......@@ -105,7 +105,7 @@ SCSI::DeviceInfo::DeviceFile SCSI::DeviceVector::statDeviceFile(std::string path
m_sysWrapper.stat(path.c_str(), &sbuf),
std::string("Could not stat file ") + path);
if (!S_ISCHR(sbuf.st_mode))
throw Exception("Device file " + path + " is not a character device");
throw castor::exception::Exception("Device file " + path + " is not a character device");
DeviceInfo::DeviceFile ret;
ret.major = major(sbuf.st_rdev);
ret.minor = minor(sbuf.st_rdev);
......@@ -153,7 +153,7 @@ void SCSI::DeviceVector::getTapeInfo(DeviceInfo & devinfo) {
if (!devinfo.st_dev.size()) {
devinfo.st_dev = std::string("/dev/") + res[1];
} else
throw Exception("Matched st device several times!");
throw castor::exception::Exception("Matched st device several times!");
/* Read the major and major number */
devinfo.st = readDeviceFile(devinfo.sysfs_entry + tapeDir+ "/"
+ std::string(dent->d_name) + "/dev");
......@@ -166,7 +166,7 @@ void SCSI::DeviceVector::getTapeInfo(DeviceInfo & devinfo) {
<< devinfo.st.major << ":" << devinfo.st.minor
<< " while " << devinfo.st_dev << " is: "
<< realFile.major << ":" << realFile.minor;
throw Exception(err.str());
throw castor::exception::Exception(err.str());
}
}
/* Check if it's the nst information */
......@@ -175,7 +175,7 @@ void SCSI::DeviceVector::getTapeInfo(DeviceInfo & devinfo) {
if (!devinfo.nst_dev.size()) {
devinfo.nst_dev = std::string("/dev/") + res[1];
} else
throw Exception("Matched nst device several times!");
throw castor::exception::Exception("Matched nst device several times!");
/* Read the major and major number */
devinfo.nst = readDeviceFile(devinfo.sysfs_entry + tapeDir + "/"
+ std::string(dent->d_name) + "/dev");
......@@ -188,7 +188,7 @@ void SCSI::DeviceVector::getTapeInfo(DeviceInfo & devinfo) {
<< devinfo.nst.major << ":" << devinfo.nst.minor
<< " while " << devinfo.st_dev << " is: "
<< realFile.major << ":" << realFile.minor;
throw Exception(err.str());
throw castor::exception::Exception(err.str());
}
}
}
......@@ -208,7 +208,7 @@ SCSI::DeviceInfo SCSI::DeviceVector::getDeviceInfo(const char * path) {
{
buf = readfile(ret.sysfs_entry + "/type");
if (!sscanf(buf.c_str(), "%d", &ret.type))
throw Exception(std::string("Could not parse file: ") + ret.sysfs_entry + "/type");
throw castor::exception::Exception(std::string("Could not parse file: ") + ret.sysfs_entry + "/type");
}
/* Get vendor (trimmed of trailing newline, not of spaces) */
{
......@@ -240,7 +240,7 @@ SCSI::DeviceInfo SCSI::DeviceVector::getDeviceInfo(const char * path) {
std::string gl(rl);
size_t pos = gl.find_last_of("/");
if (pos == std::string::npos)
throw Exception(std::string("Could not find last / in link: ") + gl +
throw castor::exception::Exception(std::string("Could not find last / in link: ") + gl +
" read from " + ret.sysfs_entry + "/generic");
ret.sg_dev = std::string("/dev/") + gl.substr(pos + 1);
}
......@@ -255,7 +255,7 @@ SCSI::DeviceInfo SCSI::DeviceVector::getDeviceInfo(const char * path) {
<< ret.sg.major << ":" << ret.sg.minor
<< " while " << ret.sg_dev << " is: "
<< realFile.major << ":" << realFile.minor;
throw Exception(err.str());
throw castor::exception::Exception(err.str());
}
/* Handle more if we have a tape device */
if (Types::tape == ret.type)
......
......@@ -29,7 +29,7 @@
#include <sys/types.h>
#include <dirent.h>
#include "../system/Wrapper.hpp"
#include "castor/tape/tapeserver/exception/Exception.hpp"
#include "castor/exception/Exception.hpp"
#include "../utils/Regex.hpp"
#include "Constants.hpp"
#include <string>
......@@ -99,9 +99,9 @@ namespace SCSI {
/**
* Exception for previous function
*/
class NotFound: public castor::tape::Exception {
class NotFound: public castor::exception::Exception {
public:
NotFound(const std::string& what): castor::tape::Exception(what) {}
NotFound(const std::string& what): castor::exception::Exception(what) {}
};
private:
castor::tape::System::virtualWrapper & m_sysWrapper;
......
......@@ -21,7 +21,7 @@
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "castor/tape/tapeserver/exception/Exception.hpp"
#include "castor/exception/Exception.hpp"
#include "Structures.hpp"
#include "Constants.hpp"
......@@ -33,11 +33,11 @@ namespace SCSI {
/**
* An exception class turning SCSI sense data into a loggable string
*/
class Exception: public castor::tape::Exception {
class Exception: public castor::exception::Exception {
public:
Exception(unsigned char status, castor::tape::SCSI::Structures::senseData_t<255> * sense,
const std::string & context = ""):
castor::tape::Exception("") {
castor::exception::Exception("") {
std::stringstream w;
w << context << (context.size()?" ":"")
<< "SCSI command failed with status "
......
......@@ -33,7 +33,7 @@
#include <cstdio>
#include "Constants.hpp"
#include "castor/tape/tapeserver/exception/Exception.hpp"
#include "castor/exception/Exception.hpp"
namespace castor {
namespace tape {
......@@ -77,7 +77,7 @@ namespace SCSI {
void setSenseBuffer(T * senseBuff)
{
if (sizeof(T) > UCHAR_MAX)
throw Exception("sense structure too big in LinuxSGIO_t::setSense");
throw castor::exception::Exception("sense structure too big in LinuxSGIO_t::setSense");
mx_sb_len = (unsigned char) sizeof(T);
sbp = (unsigned char *)senseBuff;
}
......@@ -736,7 +736,7 @@ namespace SCSI {
public:
senseData_t() {
if (sizeof(*this) > 255)
throw Exception("In SCSI::Structures::senseData_t::senseData_t(): size too big (> 255>");
throw castor::exception::Exception("In SCSI::Structures::senseData_t::senseData_t(): size too big (> 255>");
zeroStruct(this);
}
// byte 0
......@@ -817,7 +817,7 @@ namespace SCSI {
std::stringstream err;
err << "In senseData_t::getASC: no ACS with this response code or response code not supported ("
<< std::hex << std::showbase << (int)responseCode << ")";
throw Exception(err.str());
throw castor::exception::Exception(err.str());
}
}
......@@ -830,7 +830,7 @@ namespace SCSI {
std::stringstream err;
err << "In senseData_t::getASCQ: no ACSQ with this response code or response code not supported ("
<< std::hex << std::showbase << (int)responseCode << ")";
throw Exception(err.str());
throw castor::exception::Exception(err.str());
}
}
/**
......
......@@ -567,12 +567,12 @@ namespace unitTests {
ASSERT_EQ("Unknown ASC/ASCQ:00/1f", sense.getACSString());
buff[0] = 0x74;
ASSERT_THROW(sense.getASC(), castor::tape::Exception);
ASSERT_THROW(sense.getASC(), castor::exception::Exception);
ASSERT_THROW(sense.getACSString(), castor::tape::Exception);
ASSERT_THROW(sense.getACSString(), castor::exception::Exception);
try { sense.getACSString(); ASSERT_TRUE(false); }
catch (castor::tape::Exception & ex) {
catch (castor::exception::Exception & ex) {
std::string what(ex.getMessageValue());
ASSERT_NE(std::string::npos, what.find("response code not supported (0x74)"));
}
......
......@@ -29,7 +29,7 @@
#pragma once
#include "castor/legacymsg/RtcpJobRqstMsgBody.hpp"
#include "castor/tape/tapeserver/exception/Exception.hpp"
#include "castor/exception/Exception.hpp"
#include "castor/tape/tapegateway/GatewayMessage.hpp"
#include "castor/tape/tapegateway/ClientType.hpp"
#include "castor/tape/tapegateway/VolumeMode.hpp"
......
......@@ -58,7 +58,7 @@ m_request(clientRequest),m_transactionId(0) {}
//------------------------------------------------------------------------------
ClientProxy::UnexpectedResponse::
UnexpectedResponse(const castor::IObject* resp, const std::string & w):
castor::tape::Exception(w) {
castor::exception::Exception(w) {
std::string responseType = typeid(*resp).name();
int status = -1;
char * demangled = abi::__cxa_demangle(responseType.c_str(), NULL, NULL, &status);
......@@ -301,7 +301,7 @@ tapegateway::FileMigrationReportList & migrationReport,
std::stringstream mess;
mess << "End notification report: errorMessage=\""
<< err.errorMessage() << "\" errorCode=" << err.errorCode();
throw castor::tape::Exception(mess.str());
throw castor::exception::Exception(mess.str());
} catch (std::bad_cast&) {
throw UnexpectedResponse(resp.get(),
"Unexpected response to FileMigrationReportList in reportMigrationResults");
......@@ -378,7 +378,7 @@ RequestReport& report) {
std::stringstream mess;
mess << "End notification report: errorMessage=\""
<< err.errorMessage() << "\" errorCode=" << err.errorCode();
throw castor::tape::Exception(mess.str());
throw castor::exception::Exception(mess.str());
} catch (std::bad_cast&) {
throw UnexpectedResponse(resp.get(),
"Unexpected response to FileRecallReportList in reportRecallResults");
......
......@@ -24,7 +24,7 @@
#pragma once
#include "castor/legacymsg/RtcpJobRqstMsgBody.hpp"
#include "castor/tape/tapeserver/exception/Exception.hpp"
#include "castor/exception/Exception.hpp"
#include "castor/tape/tapegateway/GatewayMessage.hpp"
#include "castor/tape/tapegateway/ClientType.hpp"
#include "castor/tape/tapegateway/VolumeMode.hpp"
......@@ -130,7 +130,7 @@ namespace client {
* Exception thrown when the wrong response type was received from
* the client after a request. Extracts the type and prints it.
*/
class UnexpectedResponse: public castor::tape::Exception {
class UnexpectedResponse: public castor::exception::Exception {
public:
UnexpectedResponse(const castor::IObject * resp, const std::string & w="");
};
......@@ -138,9 +138,9 @@ namespace client {
/**
* Exception marking end of session
*/
class EndOfSession: public castor::tape::Exception {
class EndOfSession: public castor::exception::Exception {
public:
EndOfSession(std::string w=""):castor::tape::Exception(w) {}
EndOfSession(std::string w=""):castor::exception::Exception(w) {}
};
......
......@@ -52,7 +52,6 @@ add_executable(tapeserverd TapeDaemon.cpp)
target_link_libraries(tapeserverd
castorTapeServerDaemon
Exception
SCSI
System
Utils
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment