config/{Global,Block}: throw exception on parser error
This commit is contained in:
src/config
@ -21,7 +21,6 @@
|
|||||||
#include "Block.hxx"
|
#include "Block.hxx"
|
||||||
#include "Parser.hxx"
|
#include "Parser.hxx"
|
||||||
#include "Path.hxx"
|
#include "Path.hxx"
|
||||||
#include "system/FatalError.hxx"
|
|
||||||
#include "fs/AllocatedPath.hxx"
|
#include "fs/AllocatedPath.hxx"
|
||||||
#include "util/RuntimeError.hxx"
|
#include "util/RuntimeError.hxx"
|
||||||
|
|
||||||
@ -35,7 +34,7 @@ BlockParam::GetIntValue() const
|
|||||||
char *endptr;
|
char *endptr;
|
||||||
long value2 = strtol(s, &endptr, 0);
|
long value2 = strtol(s, &endptr, 0);
|
||||||
if (endptr == s || *endptr != 0)
|
if (endptr == s || *endptr != 0)
|
||||||
FormatFatalError("Not a valid number in line %i", line);
|
throw FormatRuntimeError("Not a valid number in line %i", line);
|
||||||
|
|
||||||
return value2;
|
return value2;
|
||||||
}
|
}
|
||||||
@ -47,7 +46,7 @@ BlockParam::GetUnsignedValue() const
|
|||||||
char *endptr;
|
char *endptr;
|
||||||
unsigned long value2 = strtoul(s, &endptr, 0);
|
unsigned long value2 = strtoul(s, &endptr, 0);
|
||||||
if (endptr == s || *endptr != 0)
|
if (endptr == s || *endptr != 0)
|
||||||
FormatFatalError("Not a valid number in line %i", line);
|
throw FormatRuntimeError("Not a valid number in line %i", line);
|
||||||
|
|
||||||
return (unsigned)value2;
|
return (unsigned)value2;
|
||||||
}
|
}
|
||||||
@ -59,10 +58,10 @@ BlockParam::GetPositiveValue() const
|
|||||||
char *endptr;
|
char *endptr;
|
||||||
unsigned long value2 = strtoul(s, &endptr, 0);
|
unsigned long value2 = strtoul(s, &endptr, 0);
|
||||||
if (endptr == s || *endptr != 0)
|
if (endptr == s || *endptr != 0)
|
||||||
FormatFatalError("Not a valid number in line %i", line);
|
throw FormatRuntimeError("Not a valid number in line %i", line);
|
||||||
|
|
||||||
if (value2 <= 0)
|
if (value2 <= 0)
|
||||||
FormatFatalError("Number in line %i must be positive", line);
|
throw FormatRuntimeError("Number in line %i must be positive", line);
|
||||||
|
|
||||||
return (unsigned)value2;
|
return (unsigned)value2;
|
||||||
}
|
}
|
||||||
@ -72,7 +71,7 @@ BlockParam::GetBoolValue() const
|
|||||||
{
|
{
|
||||||
bool value2;
|
bool value2;
|
||||||
if (!get_bool(value.c_str(), &value2))
|
if (!get_bool(value.c_str(), &value2))
|
||||||
FormatFatalError("%s is not a boolean value (yes, true, 1) or "
|
throw FormatRuntimeError("%s is not a boolean value (yes, true, 1) or "
|
||||||
"(no, false, 0) on line %i\n",
|
"(no, false, 0) on line %i\n",
|
||||||
name.c_str(), line);
|
name.c_str(), line);
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
#include "Domain.hxx"
|
#include "Domain.hxx"
|
||||||
#include "fs/Path.hxx"
|
#include "fs/Path.hxx"
|
||||||
#include "fs/AllocatedPath.hxx"
|
#include "fs/AllocatedPath.hxx"
|
||||||
#include "system/FatalError.hxx"
|
#include "util/RuntimeError.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -126,7 +126,7 @@ config_get_unsigned(ConfigOption option, unsigned default_value)
|
|||||||
const char *const s = param->value.c_str();
|
const char *const s = param->value.c_str();
|
||||||
value = strtol(s, &endptr, 0);
|
value = strtol(s, &endptr, 0);
|
||||||
if (endptr == s || *endptr != 0 || value < 0)
|
if (endptr == s || *endptr != 0 || value < 0)
|
||||||
FormatFatalError("Not a valid non-negative number in line %i",
|
throw FormatRuntimeError("Not a valid non-negative number in line %i",
|
||||||
param->line);
|
param->line);
|
||||||
|
|
||||||
return (unsigned)value;
|
return (unsigned)value;
|
||||||
@ -145,10 +145,11 @@ config_get_positive(ConfigOption option, unsigned default_value)
|
|||||||
const char *const s = param->value.c_str();
|
const char *const s = param->value.c_str();
|
||||||
value = strtol(s, &endptr, 0);
|
value = strtol(s, &endptr, 0);
|
||||||
if (endptr == s || *endptr != 0)
|
if (endptr == s || *endptr != 0)
|
||||||
FormatFatalError("Not a valid number in line %i", param->line);
|
throw FormatRuntimeError("Not a valid number in line %i",
|
||||||
|
param->line);
|
||||||
|
|
||||||
if (value <= 0)
|
if (value <= 0)
|
||||||
FormatFatalError("Not a positive number in line %i",
|
throw FormatRuntimeError("Not a positive number in line %i",
|
||||||
param->line);
|
param->line);
|
||||||
|
|
||||||
return (unsigned)value;
|
return (unsigned)value;
|
||||||
@ -165,7 +166,7 @@ config_get_bool(ConfigOption option, bool default_value)
|
|||||||
|
|
||||||
success = get_bool(param->value.c_str(), &value);
|
success = get_bool(param->value.c_str(), &value);
|
||||||
if (!success)
|
if (!success)
|
||||||
FormatFatalError("Expected boolean value (yes, true, 1) or "
|
throw FormatRuntimeError("Expected boolean value (yes, true, 1) or "
|
||||||
"(no, false, 0) on line %i\n",
|
"(no, false, 0) on line %i\n",
|
||||||
param->line);
|
param->line);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user