2012-07-18 20:59:03 +02:00
|
|
|
#pragma once
|
2006-09-04 23:06:23 +02:00
|
|
|
|
2012-09-11 20:45:42 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
2006-09-04 23:06:23 +02:00
|
|
|
#include <string>
|
|
|
|
#include <list>
|
|
|
|
#include <set>
|
|
|
|
|
|
|
|
#include <boost/format.hpp>
|
|
|
|
|
2014-10-20 18:15:50 +02:00
|
|
|
/* Before 4.7, gcc's std::exception uses empty throw() specifiers for
|
|
|
|
* its (virtual) destructor and what() in c++11 mode, in violation of spec
|
|
|
|
*/
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 7)
|
|
|
|
#define EXCEPTION_NEEDS_THROW_SPEC
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2006-09-04 23:06:23 +02:00
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
|
|
|
|
/* Inherit some names from other namespaces for convenience. */
|
|
|
|
using std::string;
|
|
|
|
using std::list;
|
|
|
|
using std::set;
|
|
|
|
using std::vector;
|
|
|
|
using boost::format;
|
|
|
|
|
|
|
|
|
2014-03-28 16:59:26 +01:00
|
|
|
struct FormatOrString
|
|
|
|
{
|
|
|
|
string s;
|
|
|
|
FormatOrString(const string & s) : s(s) { };
|
|
|
|
FormatOrString(const format & f) : s(f.str()) { };
|
|
|
|
FormatOrString(const char * s) : s(s) { };
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-08-12 02:29:28 +02:00
|
|
|
/* BaseError should generally not be caught, as it has Interrupted as
|
|
|
|
a subclass. Catch Error instead. */
|
2014-03-28 16:59:26 +01:00
|
|
|
class BaseError : public std::exception
|
2006-09-04 23:06:23 +02:00
|
|
|
{
|
|
|
|
protected:
|
2009-06-30 15:28:29 +02:00
|
|
|
string prefix_; // used for location traces etc.
|
2006-09-04 23:06:23 +02:00
|
|
|
string err;
|
|
|
|
public:
|
2010-12-13 17:53:23 +01:00
|
|
|
unsigned int status; // exit status
|
2014-03-28 16:59:26 +01:00
|
|
|
BaseError(const FormatOrString & fs, unsigned int status = 1);
|
2014-10-20 18:15:50 +02:00
|
|
|
#ifdef EXCEPTION_NEEDS_THROW_SPEC
|
2014-10-20 17:33:48 +02:00
|
|
|
~BaseError() throw () { };
|
|
|
|
const char * what() const throw () { return err.c_str(); }
|
2014-10-20 18:15:50 +02:00
|
|
|
#else
|
|
|
|
const char * what() const noexcept { return err.c_str(); }
|
|
|
|
#endif
|
2014-07-09 12:14:40 +02:00
|
|
|
const string & msg() const { return err; }
|
|
|
|
const string & prefix() const { return prefix_; }
|
2014-03-28 16:59:26 +01:00
|
|
|
BaseError & addPrefix(const FormatOrString & fs);
|
2006-09-04 23:06:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#define MakeError(newClass, superClass) \
|
|
|
|
class newClass : public superClass \
|
|
|
|
{ \
|
|
|
|
public: \
|
2014-03-28 16:59:26 +01:00
|
|
|
newClass(const FormatOrString & fs, unsigned int status = 1) : superClass(fs, status) { }; \
|
2006-09-04 23:06:23 +02:00
|
|
|
};
|
|
|
|
|
2007-08-12 02:29:28 +02:00
|
|
|
MakeError(Error, BaseError)
|
|
|
|
|
|
|
|
class SysError : public Error
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int errNo;
|
2014-03-28 16:59:26 +01:00
|
|
|
SysError(const FormatOrString & fs);
|
2007-08-12 02:29:28 +02:00
|
|
|
};
|
|
|
|
|
2006-09-04 23:06:23 +02:00
|
|
|
|
|
|
|
typedef list<string> Strings;
|
|
|
|
typedef set<string> StringSet;
|
|
|
|
|
|
|
|
|
|
|
|
/* Paths are just strings. */
|
|
|
|
typedef string Path;
|
|
|
|
typedef list<Path> Paths;
|
|
|
|
typedef set<Path> PathSet;
|
|
|
|
|
2014-03-28 16:59:26 +01:00
|
|
|
|
|
|
|
typedef enum {
|
2010-08-30 16:53:03 +02:00
|
|
|
lvlError = 0,
|
2006-09-04 23:06:23 +02:00
|
|
|
lvlInfo,
|
|
|
|
lvlTalkative,
|
|
|
|
lvlChatty,
|
|
|
|
lvlDebug,
|
|
|
|
lvlVomit
|
|
|
|
} Verbosity;
|
|
|
|
|
|
|
|
|
|
|
|
}
|