config/Block: GetPath() throws exception on error

This commit is contained in:
Max Kellermann
2016-10-28 23:08:42 +02:00
parent d8bcdca55a
commit e17805f208
8 changed files with 23 additions and 55 deletions

View File

@@ -23,6 +23,7 @@
#include "ConfigPath.hxx"
#include "system/FatalError.hxx"
#include "fs/AllocatedPath.hxx"
#include "util/RuntimeError.hxx"
#include "util/Error.hxx"
#include <assert.h>
@@ -91,11 +92,8 @@ ConfigBlock::GetBlockValue(const char *name, const char *default_value) const
}
AllocatedPath
ConfigBlock::GetPath(const char *name, const char *default_value,
Error &error) const
ConfigBlock::GetPath(const char *name, const char *default_value) const
{
assert(!error.IsDefined());
int line2 = line;
const char *s;
@@ -110,20 +108,15 @@ ConfigBlock::GetPath(const char *name, const char *default_value,
s = default_value;
}
Error error;
AllocatedPath path = ParsePath(s, error);
if (gcc_unlikely(path.IsNull()))
error.FormatPrefix("Invalid path in \"%s\" at line %i: ",
name, line2);
throw FormatRuntimeError("Invalid path in \"%s\" at line %i: %s",
name, line2, error.GetMessage());
return path;
}
AllocatedPath
ConfigBlock::GetPath(const char *name, Error &error) const
{
return GetPath(name, nullptr, error);
}
int
ConfigBlock::GetBlockValue(const char *name, int default_value) const
{

View File

@@ -111,11 +111,11 @@ struct ConfigBlock {
/**
* Same as config_get_path(), but looks up the setting in the
* specified block.
*
* Throws #std::runtime_error on error.
*/
AllocatedPath GetPath(const char *name, const char *default_value,
Error &error) const;
AllocatedPath GetPath(const char *name, Error &error) const;
AllocatedPath GetPath(const char *name,
const char *default_value=nullptr) const;
gcc_pure
int GetBlockValue(const char *name, int default_value) const;