aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-22 07:29:34 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-22 07:29:34 +0000
commitf40c1a8eb9e46fd3bbfd70981288aba3e8915510 (patch)
tree021f79578a2788079a8d18b155dec76ccbb67ed7
parent3dff66adc5903d575c63da59e034742ac17a8cad (diff)
downloadpaludis-f40c1a8eb9e46fd3bbfd70981288aba3e8915510.tar.gz
paludis-f40c1a8eb9e46fd3bbfd70981288aba3e8915510.tar.xz
Improve exception messages from KeyValueConfigFile. Move KeyValueConfigFileError into key_value_config_file. Make ConfigFileError descend from ConfigurationError rather than directly from Exception.
-rw-r--r--paludis/config_file.cc2
-rw-r--r--paludis/config_file.hh3
-rw-r--r--paludis/files.m41
-rw-r--r--paludis/key_value_config_file.cc20
-rw-r--r--paludis/key_value_config_file.hh14
-rw-r--r--paludis/key_value_config_file_error.cc29
-rw-r--r--paludis/key_value_config_file_error.hh35
7 files changed, 30 insertions, 74 deletions
diff --git a/paludis/config_file.cc b/paludis/config_file.cc
index 0c40c19..997e9b0 100644
--- a/paludis/config_file.cc
+++ b/paludis/config_file.cc
@@ -27,7 +27,7 @@
using namespace paludis;
ConfigFileError::ConfigFileError(const std::string & message) throw () :
- Exception("Config file error: " + message)
+ ConfigurationError("Config file error: " + message)
{
}
diff --git a/paludis/config_file.hh b/paludis/config_file.hh
index 95742db..85f0aa6 100644
--- a/paludis/config_file.hh
+++ b/paludis/config_file.hh
@@ -22,6 +22,7 @@
#define PALUDIS_GUARD_PALUDIS_CONFIG_FILE_HH 1
#include <paludis/instantiation_policy.hh>
+#include <paludis/configuration_error.hh>
#include <istream>
#include <list>
#include <string>
@@ -41,7 +42,7 @@ namespace paludis
* \ingroup Exception
* \ingroup ConfigFile
*/
- class ConfigFileError : public Exception
+ class ConfigFileError : public ConfigurationError
{
public:
/**
diff --git a/paludis/files.m4 b/paludis/files.m4
index 0abc353..ef132a4 100644
--- a/paludis/files.m4
+++ b/paludis/files.m4
@@ -63,7 +63,6 @@ add(`is_file_with_extension', `hh', `cc', `test', `testscript')
add(`iterator_utilities', `hh', `cc')
add(`join', `hh', `cc', `test')
add(`key_value_config_file', `hh', `cc', `test')
-add(`key_value_config_file_error', `hh', `cc')
add(`keyword_name', `hh', `cc')
add(`line_config_file', `hh', `cc', `test')
add(`mask_reasons', `hh', `cc')
diff --git a/paludis/key_value_config_file.cc b/paludis/key_value_config_file.cc
index 80006e5..c031227 100644
--- a/paludis/key_value_config_file.cc
+++ b/paludis/key_value_config_file.cc
@@ -19,10 +19,16 @@
*/
#include "key_value_config_file.hh"
-#include "key_value_config_file_error.hh"
using namespace paludis;
+KeyValueConfigFileError::KeyValueConfigFileError(const std::string & msg,
+ const std::string & filename) throw () :
+ ConfigurationError("Key/Value config file error" +
+ (filename.empty() ? ": " : "in file '" + filename + "': ") + msg)
+{
+}
+
KeyValueConfigFile::KeyValueConfigFile(std::istream * const s) :
ConfigFile(s)
{
@@ -66,7 +72,7 @@ KeyValueConfigFile::replace_variables(const std::string & s) const
if ('\\' == s[p])
{
if (++p >= s.length())
- throw KeyValueConfigFileError("Backslash not followed by a character");
+ throw KeyValueConfigFileError("Backslash not followed by a character", filename());
r += s[p++];
}
else if ('$' != s[p])
@@ -75,13 +81,13 @@ KeyValueConfigFile::replace_variables(const std::string & s) const
{
std::string name;
if (++p >= s.length())
- throw KeyValueConfigFileError("Dollar not followed by a character");
+ throw KeyValueConfigFileError("Dollar not followed by a character", filename());
if ('{' == s[p])
{
std::string::size_type q;
if (std::string::npos == ((q = s.find("}", p))))
- throw KeyValueConfigFileError("Closing } not found");
+ throw KeyValueConfigFileError("Closing } not found", filename());
name = s.substr(p + 1, q - p - 1);
p = q + 1;
@@ -100,7 +106,7 @@ KeyValueConfigFile::replace_variables(const std::string & s) const
}
if (name.empty())
- throw KeyValueConfigFileError("Empty variable name");
+ throw KeyValueConfigFileError("Empty variable name", filename());
r += get(name);
}
@@ -119,9 +125,9 @@ KeyValueConfigFile::strip_quotes(const std::string & s) const
if (std::string::npos != std::string("'\"").find(s[0]))
{
if (s.length() < 2)
- throw KeyValueConfigFileError("Unterminated quote");
+ throw KeyValueConfigFileError("Unterminated quote", filename());
if (s[s.length() - 1] != s[0])
- throw KeyValueConfigFileError("Mismatched quote");
+ throw KeyValueConfigFileError("Mismatched quote", filename());
return s.substr(1, s.length() - 2);
}
else
diff --git a/paludis/key_value_config_file.hh b/paludis/key_value_config_file.hh
index 67858d3..cff2e43 100644
--- a/paludis/key_value_config_file.hh
+++ b/paludis/key_value_config_file.hh
@@ -34,6 +34,20 @@
namespace paludis
{
/**
+ * A KeyValueConfigFileError is thrown if bad data is encountered in
+ * a ConfigFile.
+ *
+ * \ingroup ConfigFile
+ * \ingroup Exception
+ */
+ class KeyValueConfigFileError : public ConfigurationError
+ {
+ public:
+ KeyValueConfigFileError(const std::string & message,
+ const std::string & filename = "") throw ();
+ };
+
+ /**
* A KeyValueConfigFile is a ConfigFile that provides access to the
* normalised lines. Do not subclass.
*
diff --git a/paludis/key_value_config_file_error.cc b/paludis/key_value_config_file_error.cc
deleted file mode 100644
index 64d133e..0000000
--- a/paludis/key_value_config_file_error.cc
+++ /dev/null
@@ -1,29 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
- *
- * This file is part of the Paludis package manager. Paludis is free software;
- * you can redistribute it and/or modify it under the terms of the GNU General
- * Public License as published by the Free Software Foundation; either version
- * 2 of the License, or (at your option) any later version.
- *
- * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "key_value_config_file_error.hh"
-
-using namespace paludis;
-
-KeyValueConfigFileError::KeyValueConfigFileError(const std::string & msg) throw () :
- ConfigurationError("Key/Value config file error: " + msg)
-{
-}
-
diff --git a/paludis/key_value_config_file_error.hh b/paludis/key_value_config_file_error.hh
deleted file mode 100644
index 9962857..0000000
--- a/paludis/key_value_config_file_error.hh
+++ /dev/null
@@ -1,35 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
- *
- * This file is part of the Paludis package manager. Paludis is free software;
- * you can redistribute it and/or modify it under the terms of the GNU General
- * Public License as published by the Free Software Foundation; either version
- * 2 of the License, or (at your option) any later version.
- *
- * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef PALUDIS_GUARD_PALUDIS_KEY_VALUE_CONFIG_FILE_ERROR_HH
-#define PALUDIS_GUARD_PALUDIS_KEY_VALUE_CONFIG_FILE_ERROR_HH 1
-
-#include <paludis/configuration_error.hh>
-
-namespace paludis
-{
- class KeyValueConfigFileError : public ConfigurationError
- {
- public:
- KeyValueConfigFileError(const std::string & message) throw ();
- };
-}
-
-#endif