Skip to content

Commit 740569c

Browse files
committed
chore: Error improvement and tidy
1 parent a97f568 commit 740569c

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

include/mrdox/Support/Error.hpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <mrdox/Support/Format.hpp>
1717
#include <exception>
1818
#include <iterator>
19+
#include <source_location>
1920
#include <string>
2021
#include <string_view>
2122
#include <type_traits>
@@ -37,7 +38,8 @@ class [[nodiscard]] MRDOX_DECL
3738
static
3839
std::string
3940
appendSourceLocation(
40-
std::string&&, std::source_location const&);
41+
std::string&&,
42+
std::source_location const&);
4143

4244
public:
4345
/** Constructor.
@@ -76,9 +78,9 @@ class [[nodiscard]] MRDOX_DECL
7678
std::string reason,
7779
std::source_location loc =
7880
std::source_location::current())
79-
: message_(appendSourceLocation(
80-
std::string(reason), loc))
81+
: message_(appendSourceLocation(std::string(reason), loc))
8182
, reason_(std::move(reason))
83+
, loc_(loc)
8284
{
8385
MRDOX_ASSERT(! message_.empty());
8486
}
@@ -101,7 +103,10 @@ class [[nodiscard]] MRDOX_DECL
101103
}
102104

103105
explicit
104-
Error(std::vector<Error> const& errors);
106+
Error(
107+
std::vector<Error> const& errors,
108+
std::source_location loc =
109+
std::source_location::current());
105110

106111
/** Return true if this holds an error.
107112
*/

source/Support/Error.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ appendSourceLocation(
4040

4141
Error::
4242
Error(
43-
std::vector<Error> const& errors)
43+
std::vector<Error> const& errors,
44+
std::source_location loc)
4445
{
4546
MRDOX_ASSERT(errors.size() > 0);
4647
if(errors.size() == 1)
@@ -56,6 +57,8 @@ Error(
5657
message_.append(err.message());
5758
message_.push_back('\n');
5859
}
60+
reason_ = message_;
61+
loc_ = loc;
5962
}
6063

6164
SourceLocation::

0 commit comments

Comments
 (0)