summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sbuild/sbuild-custom-error.h66
-rw-r--r--sbuild/sbuild-error.h21
-rw-r--r--sbuild/sbuild-error.tcc45
-rw-r--r--sbuild/sbuild-parse-error.h52
4 files changed, 122 insertions, 62 deletions
diff --git a/sbuild/sbuild-custom-error.h b/sbuild/sbuild-custom-error.h
index 818fe9f5..316b4108 100644
--- a/sbuild/sbuild-custom-error.h
+++ b/sbuild/sbuild-custom-error.h
@@ -41,8 +41,8 @@ namespace sbuild
* @param error the error code.
*/
custom_error (error_type error):
- sbuild::error<T>(format_error(null(), null(), null(), error, null(), null()),
- format_reason(null(), null(), null(), error, null(), null()))
+ sbuild::error<T>(format_error(null(), null(), null(), error, null(), null(), null()),
+ format_reason(null(), null(), null(), error, null(), null(), null()))
{
}
@@ -55,8 +55,8 @@ namespace sbuild
template<typename C>
custom_error (C const& context,
error_type error):
- sbuild::error<T>(format_error(context, null(), null(), error, null(), null()),
- format_reason(context, null(), null(), error, null(), null()))
+ sbuild::error<T>(format_error(context, null(), null(), error, null(), null(), null()),
+ format_reason(context, null(), null(), error, null(), null(), null()))
{
}
@@ -69,8 +69,8 @@ namespace sbuild
template<typename D>
custom_error (error_type error,
D const& detail):
- sbuild::error<T>(format_error(null(), null(), null(), error, detail, null()),
- format_reason(null(), null(), null(), error, detail, null()))
+ sbuild::error<T>(format_error(null(), null(), null(), error, detail, null(), null()),
+ format_reason(null(), null(), null(), error, detail, null(), null()))
{
}
@@ -85,8 +85,26 @@ namespace sbuild
custom_error (error_type error,
D const& detail,
E const& detail2):
- sbuild::error<T>(format_error(null(), null(), null(), error, detail, detail2),
- format_reason(null(), null(), null(), error, detail, detail2))
+ sbuild::error<T>(format_error(null(), null(), null(), error, detail, detail2, null()),
+ format_reason(null(), null(), null(), error, detail, detail2, null()))
+ {
+ }
+
+ /**
+ * The constructor.
+ *
+ * @param error the error code.
+ * @param detail the details of the error.
+ * @param detail2 additional details of the error.
+ * @param detail3 additional details of the error.
+ */
+ template<typename D, typename E, typename F>
+ custom_error (error_type error,
+ D const& detail,
+ E const& detail2,
+ F const& detail3):
+ sbuild::error<T>(format_error(null(), null(), null(), error, detail, detail2, detail3),
+ format_reason(null(), null(), null(), error, detail, detail2, detail3))
{
}
@@ -101,8 +119,8 @@ namespace sbuild
custom_error (C const& context,
error_type error,
D const& detail):
- sbuild::error<T>(format_error(context, null(), null(), error, detail, null()),
- format_reason(context, null(), null(), error, detail, null()))
+ sbuild::error<T>(format_error(context, null(), null(), error, detail, null(), null()),
+ format_reason(context, null(), null(), error, detail, null(), null()))
{
}
@@ -119,8 +137,8 @@ namespace sbuild
error_type error,
D const& detail,
E const& detail2):
- sbuild::error<T>(format_error(context, null(), null(), error, detail, detail2),
- format_reason(context, null(), null(), error, detail, detail2))
+ sbuild::error<T>(format_error(context, null(), null(), error, detail, detail2, null()),
+ format_reason(context, null(), null(), error, detail, detail2, null()))
{
}
@@ -137,8 +155,8 @@ namespace sbuild
D const& context2,
error_type error,
E const& detail):
- sbuild::error<T>(format_error(context1, context2, null(), error, detail, null()),
- format_reason(context1, context2, null(), error, detail, null()))
+ sbuild::error<T>(format_error(context1, context2, null(), error, detail, null(), null()),
+ format_reason(context1, context2, null(), error, detail, null(), null()))
{
}
@@ -157,8 +175,8 @@ namespace sbuild
error_type error,
E const& detail,
F const& detail2):
- sbuild::error<T>(format_error(context1, context2, null(), error, detail, detail2),
- format_reason(context1, context2, null(), error, detail, detail2))
+ sbuild::error<T>(format_error(context1, context2, null(), error, detail, detail2, null()),
+ format_reason(context1, context2, null(), error, detail, detail2, null()))
{
}
@@ -168,8 +186,8 @@ namespace sbuild
* @param error the error.
*/
custom_error (std::runtime_error const& error):
- sbuild::error<T>(sbuild::error<T>::format_error(null(), null(), null(), error, null(), null()),
- sbuild::error<T>::format_reason(null(), null(), null(), error, null(), null()))
+ sbuild::error<T>(sbuild::error<T>::format_error(null(), null(), null(), error, null(), null(), null()),
+ sbuild::error<T>::format_reason(null(), null(), null(), error, null(), null(), null()))
{
}
@@ -179,8 +197,8 @@ namespace sbuild
* @param error the error.
*/
custom_error (error_base const& error):
- sbuild::error<T>(sbuild::error<T>::format_error(null(), null(), null(), error, null(), null()),
- sbuild::error<T>::format_reason(null(), null(), null(), error, null(), null()))
+ sbuild::error<T>(sbuild::error<T>::format_error(null(), null(), null(), error, null(), null(), null()),
+ sbuild::error<T>::format_reason(null(), null(), null(), error, null(), null(), null()))
{
}
@@ -193,8 +211,8 @@ namespace sbuild
template<typename C>
custom_error (C const& context,
std::runtime_error const& error):
- sbuild::error<T>(sbuild::error<T>::format_error(context, null(), null(), error, null(), null()),
- sbuild::error<T>::format_reason(context, null(), null(), error, null(), null()))
+ sbuild::error<T>(sbuild::error<T>::format_error(context, null(), null(), error, null(), null(), null()),
+ sbuild::error<T>::format_reason(context, null(), null(), error, null(), null(), null()))
{
}
@@ -207,8 +225,8 @@ namespace sbuild
template<typename C>
custom_error (C const& context,
error_base const& error):
- sbuild::error<T>(sbuild::error<T>::format_error(context, null(), null(), error, null(), null()),
- sbuild::error<T>::format_reason(context, null(), null(), error, null(), null()))
+ sbuild::error<T>(sbuild::error<T>::format_error(context, null(), null(), error, null(), null(), null()),
+ sbuild::error<T>::format_reason(context, null(), null(), error, null(), null(), null()))
{
}
diff --git a/sbuild/sbuild-error.h b/sbuild/sbuild-error.h
index fe548d63..b55b65ce 100644
--- a/sbuild/sbuild-error.h
+++ b/sbuild/sbuild-error.h
@@ -164,19 +164,22 @@ namespace sbuild
* @param error the error code.
* @param detail1 details of the error.
* @param detail2 additional details of the error.
+ * @param detail3 additional details of the error.
* @returns a translated error message.
*
* @todo Merge the logic shared between the two specialisations to
* prevent code duplication.
*/
- template <typename A, typename B, typename C, typename D, typename E>
+ template <typename A, typename B, typename C,
+ typename D, typename E, typename F>
static std::string
format_error (A const& context1,
B const& context2,
C const& context3,
error_type error,
D const& detail1,
- E const& detail2);
+ E const& detail2,
+ F const& detail3);
/**
* Format an error message.
@@ -187,16 +190,19 @@ namespace sbuild
* @param error the error code.
* @param detail1 details of the error.
* @param detail2 additional details of the error.
+ * @param detail3 additional details of the error.
* @returns a translated error message.
*/
- template <typename A, typename B, typename C, typename D, typename E>
+ template <typename A, typename B, typename C,
+ typename D, typename E, typename F>
static std::string
format_error (A const& context1,
B const& context2,
C const& context3,
std::runtime_error const& error,
D const& detail1,
- E const& detail2);
+ E const& detail2,
+ F const& detail3);
/**
* Format an reason string.
@@ -207,16 +213,19 @@ namespace sbuild
* @param error the error or error code.
* @param detail1 details of the error.
* @param detail2 additional details of the error.
+ * @param detail3 additional details of the error.
* @returns a translated error message.
*/
- template <typename A, typename B, typename C, typename R, typename D, typename E>
+ template <typename A, typename B, typename C,
+ typename R, typename D, typename E, typename F>
static std::string
format_reason (A const& context1,
B const& context2,
C const& context3,
R const& error,
D const& detail1,
- E const& detail2);
+ E const& detail2,
+ F const& detail3);
/**
* Add detail to format string.
diff --git a/sbuild/sbuild-error.tcc b/sbuild/sbuild-error.tcc
index 3c684a7b..014ae996 100644
--- a/sbuild/sbuild-error.tcc
+++ b/sbuild/sbuild-error.tcc
@@ -24,14 +24,16 @@
#include <sbuild/sbuild-null.h>
template <typename T>
-template <typename A, typename B, typename C, typename D, typename E>
+template <typename A, typename B, typename C,
+ typename D, typename E, typename F>
inline std::string
sbuild::error<T>::format_error (A const& context1,
B const& context2,
C const& context3,
error_type error,
D const& detail1,
- E const& detail2)
+ E const& detail2,
+ F const& detail3)
{
std::string format;
std::string msg(get_error(error));
@@ -95,6 +97,19 @@ sbuild::error<T>::format_error (A const& context1,
nargs = 5;
}
+ if (msg.find("%6%") != std::string::npos)
+ {
+ nargs = 6;
+ }
+ else if (typeid(detail3) != typeid(sbuild::null))
+ {
+ if (msg.empty() && nargs < 4)
+ format += "%6%";
+ else
+ format += ": %6%";
+ nargs = 6;
+ }
+
boost::format fmt(format);
if (nargs >= 1)
add_detail(fmt, context1);
@@ -106,19 +121,23 @@ sbuild::error<T>::format_error (A const& context1,
add_detail(fmt, detail1);
if (nargs >= 5)
add_detail(fmt, detail2);
+ if (nargs >= 6)
+ add_detail(fmt, detail3);
return fmt.str();
}
template <typename T>
-template <typename A, typename B, typename C, typename D, typename E>
+template <typename A, typename B, typename C,
+ typename D, typename E, typename F>
inline std::string
sbuild::error<T>::format_error (A const& context1,
B const& context2,
C const& context3,
std::runtime_error const& error,
D const& detail1,
- E const& detail2)
+ E const& detail2,
+ F const& detail3)
{
std::string format;
std::string msg(error.what());
@@ -163,6 +182,15 @@ sbuild::error<T>::format_error (A const& context1,
nargs = 5;
}
+ if (typeid(detail3) != typeid(sbuild::null))
+ {
+ if (msg.empty() && nargs < 4)
+ format += "%6%";
+ else
+ format += ": %6%";
+ nargs = 6;
+ }
+
boost::format fmt(format);
if (nargs >= 1)
add_detail(fmt, context1);
@@ -174,6 +202,8 @@ sbuild::error<T>::format_error (A const& context1,
add_detail(fmt, detail1);
if (nargs >= 5)
add_detail(fmt, detail2);
+ if (nargs >= 6)
+ add_detail(fmt, detail3);
return fmt.str();
}
@@ -189,14 +219,16 @@ sbuild::error<T>::add_detail(boost::format& fmt,
}
template <typename T>
-template <typename A, typename B, typename C, typename R, typename D, typename E>
+template <typename A, typename B, typename C, typename R,
+ typename D, typename E, typename F>
inline std::string
sbuild::error<T>::format_reason (A const& context1,
B const& context2,
C const& context3,
R const& error,
D const& detail1,
- E const& detail2)
+ E const& detail2,
+ F const& detail3)
{
std::string reason;
@@ -206,6 +238,7 @@ sbuild::error<T>::format_reason (A const& context1,
add_reason(reason, error);
add_reason(reason, detail1);
add_reason(reason, detail2);
+ add_reason(reason, detail3);
return reason;
}
diff --git a/sbuild/sbuild-parse-error.h b/sbuild/sbuild-parse-error.h
index 28597a39..b966d317 100644
--- a/sbuild/sbuild-parse-error.h
+++ b/sbuild/sbuild-parse-error.h
@@ -46,8 +46,8 @@ namespace sbuild
template<typename C>
parse_error (C const& context,
error_type error):
- sbuild::error<T>(format_error(context, null(), null(), error, null(), null()),
- format_reason(context, null(), null(), error, null(), null()))
+ sbuild::error<T>(format_error(context, null(), null(), error, null(), null(), null()),
+ format_reason(context, null(), null(), error, null(), null(), null()))
{
}
@@ -60,8 +60,8 @@ namespace sbuild
template<typename D>
parse_error (error_type error,
D const& detail):
- sbuild::error<T>(format_error(null(), null(), null(), error, detail, null()),
- format_reason(null(), null(), null(), error, detail, null()))
+ sbuild::error<T>(format_error(null(), null(), null(), error, detail, null(), null()),
+ format_reason(null(), null(), null(), error, detail, null(), null()))
{
}
@@ -76,8 +76,8 @@ namespace sbuild
parse_error (size_t line,
error_type error,
D const& detail):
- sbuild::error<T>(format_error(line, null(), null(), error, detail, null()),
- format_reason(line, null(), null(), error, detail, null()))
+ sbuild::error<T>(format_error(line, null(), null(), error, detail, null(), null()),
+ format_reason(line, null(), null(), error, detail, null(), null()))
{
}
@@ -94,8 +94,8 @@ namespace sbuild
std::string const& group,
error_type error,
D const& detail):
- sbuild::error<T>(format_error(line, group, null(), error, detail, null()),
- format_reason(line, group, null(), error, detail, null()))
+ sbuild::error<T>(format_error(line, group, null(), error, detail, null(), null()),
+ format_reason(line, group, null(), error, detail, null(), null()))
{
}
@@ -114,8 +114,8 @@ namespace sbuild
std::string const& key,
error_type error,
D const& detail):
- sbuild::error<T>(format_error(line, group, key, error, detail, null()),
- format_reason(line, group, key, error, detail, null()))
+ sbuild::error<T>(format_error(line, group, key, error, detail, null(), null()),
+ format_reason(line, group, key, error, detail, null(), null()))
{
}
@@ -130,8 +130,8 @@ namespace sbuild
parse_error (std::string const& group,
error_type error,
D const& detail):
- sbuild::error<T>(format_error(group, null(), null(), error, detail, null()),
- format_reason(group, null(), null(), error, detail, null()))
+ sbuild::error<T>(format_error(group, null(), null(), error, detail, null(), null()),
+ format_reason(group, null(), null(), error, detail, null(), null()))
{
}
@@ -148,8 +148,8 @@ namespace sbuild
std::string const& key,
error_type error,
D const& detail):
- sbuild::error<T>(format_error(group, key, null(), error, detail, null()),
- format_reason(group, key, null(), error, detail, null()))
+ sbuild::error<T>(format_error(group, key, null(), error, detail, null(), null()),
+ format_reason(group, key, null(), error, detail, null(), null()))
{
}
@@ -162,8 +162,8 @@ namespace sbuild
template<typename C>
parse_error (C const& context,
std::runtime_error const& error):
- sbuild::error<T>(sbuild::error<T>::format_error(context, null(), null(), error, null(), null()),
- sbuild::error<T>::format_reason(context, null(), null(), error, null(), null()))
+ sbuild::error<T>(sbuild::error<T>::format_error(context, null(), null(), error, null(), null(), null()),
+ sbuild::error<T>::format_reason(context, null(), null(), error, null(), null(), null()))
{
}
@@ -175,8 +175,8 @@ namespace sbuild
*/
parse_error (size_t line,
std::runtime_error const& error):
- sbuild::error<T>(sbuild::error<T>::format_error(line, null(), null(), error, null(), null()),
- sbuild::error<T>::format_reason(line, null(), null(), error, null(), null()))
+ sbuild::error<T>(sbuild::error<T>::format_error(line, null(), null(), error, null(), null(), null()),
+ sbuild::error<T>::format_reason(line, null(), null(), error, null(), null(), null()))
{
}
@@ -190,8 +190,8 @@ namespace sbuild
parse_error (size_t line,
std::string const& group,
std::runtime_error const& error):
- sbuild::error<T>(sbuild::error<T>::format_error(line, group, null(), error, null(), null()),
- sbuild::error<T>::format_reason(line, group, null(), error, null(), null()))
+ sbuild::error<T>(sbuild::error<T>::format_error(line, group, null(), error, null(), null(), null()),
+ sbuild::error<T>::format_reason(line, group, null(), error, null(), null(), null()))
{
}
@@ -207,8 +207,8 @@ namespace sbuild
std::string const& group,
std::string const& key,
std::runtime_error const& error):
- sbuild::error<T>(sbuild::error<T>::format_error(line, group, key, error, null(), null()),
- sbuild::error<T>::format_reason(line, group, key, error, null(), null()))
+ sbuild::error<T>(sbuild::error<T>::format_error(line, group, key, error, null(), null(), null()),
+ sbuild::error<T>::format_reason(line, group, key, error, null(), null(), null()))
{
}
@@ -220,8 +220,8 @@ namespace sbuild
*/
parse_error (std::string const& group,
std::runtime_error const& error):
- sbuild::error<T>(sbuild::error<T>::format_error(group, null(), null(), error, null(), null()),
- sbuild::error<T>::format_reason(group, null(), null(), error, null(), null()))
+ sbuild::error<T>(sbuild::error<T>::format_error(group, null(), null(), error, null(), null(), null()),
+ sbuild::error<T>::format_reason(group, null(), null(), error, null(), null(), null()))
{
}
@@ -235,8 +235,8 @@ namespace sbuild
parse_error (std::string const& group,
std::string const& key,
std::runtime_error const& error):
- sbuild::error<T>(sbuild::error<T>::format_error(group, key, null(), error, null(), null()),
- sbuild::error<T>::format_reason(group, key, null(), error, null(), null()))
+ sbuild::error<T>(sbuild::error<T>::format_error(group, key, null(), error, null(), null(), null()),
+ sbuild::error<T>::format_reason(group, key, null(), error, null(), null(), null()))
{
}