Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
d13a6445
Commit
d13a6445
authored
Jul 16, 2018
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
config/File: use nested exception to annotate file name and line number
parent
816603fd
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
16 deletions
+16
-16
File.cxx
src/config/File.cxx
+15
-15
File.hxx
src/config/File.hxx
+1
-1
No files found.
src/config/File.cxx
View file @
d13a6445
/*
/*
* Copyright 2003-201
7
The Music Player Daemon Project
* Copyright 2003-201
8
The Music Player Daemon Project
* http://www.musicpd.org
* http://www.musicpd.org
*
*
* This program is free software; you can redistribute it and/or modify
* This program is free software; you can redistribute it and/or modify
...
@@ -65,7 +65,7 @@ config_read_name_value(ConfigBlock &block, char *input, unsigned line)
...
@@ -65,7 +65,7 @@ config_read_name_value(ConfigBlock &block, char *input, unsigned line)
static
ConfigBlock
*
static
ConfigBlock
*
config_read_block
(
BufferedReader
&
reader
)
config_read_block
(
BufferedReader
&
reader
)
try
{
{
std
::
unique_ptr
<
ConfigBlock
>
block
(
new
ConfigBlock
(
reader
.
GetLineNumber
()));
std
::
unique_ptr
<
ConfigBlock
>
block
(
new
ConfigBlock
(
reader
.
GetLineNumber
()));
while
(
true
)
{
while
(
true
)
{
...
@@ -93,8 +93,6 @@ try {
...
@@ -93,8 +93,6 @@ try {
config_read_name_value
(
*
block
,
line
,
config_read_name_value
(
*
block
,
line
,
reader
.
GetLineNumber
());
reader
.
GetLineNumber
());
}
}
}
catch
(...)
{
std
::
throw_with_nested
(
FormatRuntimeError
(
"Error in line %u"
,
reader
.
GetLineNumber
()));
}
}
gcc_nonnull_all
gcc_nonnull_all
...
@@ -130,13 +128,11 @@ ReadConfigBlock(ConfigData &config_data, BufferedReader &reader,
...
@@ -130,13 +128,11 @@ ReadConfigBlock(ConfigData &config_data, BufferedReader &reader,
/* now parse the block or the value */
/* now parse the block or the value */
if
(
tokenizer
.
CurrentChar
()
!=
'{'
)
if
(
tokenizer
.
CurrentChar
()
!=
'{'
)
throw
FormatRuntimeError
(
"line %u: '{' expected"
,
throw
std
::
runtime_error
(
"'{' expected"
);
reader
.
GetLineNumber
());
char
*
line
=
StripLeft
(
tokenizer
.
Rest
()
+
1
);
char
*
line
=
StripLeft
(
tokenizer
.
Rest
()
+
1
);
if
(
*
line
!=
0
&&
*
line
!=
CONF_COMMENT
)
if
(
*
line
!=
0
&&
*
line
!=
CONF_COMMENT
)
throw
FormatRuntimeError
(
"line %u: Unknown tokens after '{'"
,
throw
std
::
runtime_error
(
"Unknown tokens after '{'"
);
reader
.
GetLineNumber
());
auto
*
param
=
config_read_block
(
reader
);
auto
*
param
=
config_read_block
(
reader
);
assert
(
param
!=
nullptr
);
assert
(
param
!=
nullptr
);
...
@@ -177,12 +173,10 @@ ReadConfigParam(ConfigData &config_data, BufferedReader &reader,
...
@@ -177,12 +173,10 @@ ReadConfigParam(ConfigData &config_data, BufferedReader &reader,
const
char
*
value
=
tokenizer
.
NextString
();
const
char
*
value
=
tokenizer
.
NextString
();
if
(
value
==
nullptr
)
if
(
value
==
nullptr
)
throw
FormatRuntimeError
(
"line %u: Value missing"
,
throw
std
::
runtime_error
(
"Value missing"
);
reader
.
GetLineNumber
());
if
(
!
tokenizer
.
IsEnd
()
&&
tokenizer
.
CurrentChar
()
!=
CONF_COMMENT
)
if
(
!
tokenizer
.
IsEnd
()
&&
tokenizer
.
CurrentChar
()
!=
CONF_COMMENT
)
throw
FormatRuntimeError
(
"line %u: Unknown tokens after value"
,
throw
std
::
runtime_error
(
"Unknown tokens after value"
);
reader
.
GetLineNumber
());
auto
*
param
=
new
ConfigParam
(
value
,
reader
.
GetLineNumber
());
auto
*
param
=
new
ConfigParam
(
value
,
reader
.
GetLineNumber
());
Append
(
head
,
param
);
Append
(
head
,
param
);
...
@@ -219,9 +213,8 @@ ReadConfigFile(ConfigData &config_data, BufferedReader &reader)
...
@@ -219,9 +213,8 @@ ReadConfigFile(ConfigData &config_data, BufferedReader &reader)
ReadConfigBlock
(
config_data
,
reader
,
name
,
bo
,
ReadConfigBlock
(
config_data
,
reader
,
name
,
bo
,
tokenizer
);
tokenizer
);
}
else
{
}
else
{
throw
FormatRuntimeError
(
"unrecognized parameter in config file at "
throw
FormatRuntimeError
(
"unrecognized parameter: %s
\n
"
,
"line %u: %s
\n
"
,
name
);
reader
.
GetLineNumber
(),
name
);
}
}
}
}
}
}
...
@@ -237,5 +230,12 @@ ReadConfigFile(ConfigData &config_data, Path path)
...
@@ -237,5 +230,12 @@ ReadConfigFile(ConfigData &config_data, Path path)
FileReader
file
(
path
);
FileReader
file
(
path
);
BufferedReader
reader
(
file
);
BufferedReader
reader
(
file
);
try
{
ReadConfigFile
(
config_data
,
reader
);
ReadConfigFile
(
config_data
,
reader
);
}
catch
(...)
{
std
::
throw_with_nested
(
FormatRuntimeError
(
"Error in %s line %u"
,
path_utf8
.
c_str
(),
reader
.
GetLineNumber
()));
}
}
}
src/config/File.hxx
View file @
d13a6445
/*
/*
* Copyright 2003-201
7
The Music Player Daemon Project
* Copyright 2003-201
8
The Music Player Daemon Project
* http://www.musicpd.org
* http://www.musicpd.org
*
*
* This program is free software; you can redistribute it and/or modify
* This program is free software; you can redistribute it and/or modify
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment