@@ -55,17 +55,52 @@ configuration_or_error configuration_loader::watch_and_load_for_file(
55
55
.error = std::string (),
56
56
.token = const_cast <void *>(token),
57
57
});
58
- configuration_or_error config =
59
- this ->find_and_load_config_file_for_input (file_path.c_str ());
60
- if (!config.error .empty ()) {
61
- watch.error = config.error ;
62
- }
63
- return config;
58
+ return boost::leaf::try_handle_all (
59
+ [&]() -> boost::leaf::result<configuration_or_error> {
60
+ return this ->find_and_load_config_file_for_input (file_path.c_str ());
61
+ },
62
+ make_canonicalize_path_error_handlers (
63
+ [&](std::string&& message) -> configuration_or_error {
64
+ watch.error = message;
65
+ return configuration_or_error (std::move (message));
66
+ }),
67
+ make_read_file_error_handlers ([&](std::string&& message) {
68
+ watch.error = message;
69
+ return configuration_or_error (std::move (message));
70
+ }),
71
+ [&](boost::leaf::e_errno error) {
72
+ const char * message = std::strerror (error.value );
73
+ watch.error = message;
74
+ return configuration_or_error (message);
75
+ },
76
+ [&]() {
77
+ QLJS_ASSERT (false );
78
+ const char * message = " unknown error" ;
79
+ watch.error = message;
80
+ return configuration_or_error (message);
81
+ });
64
82
}
65
83
66
84
configuration_or_error configuration_loader::load_for_file (
67
85
const std::string& file_path) {
68
- return this ->find_and_load_config_file_for_input (file_path.c_str ());
86
+ return boost::leaf::try_handle_all (
87
+ [&]() -> boost::leaf::result<configuration_or_error> {
88
+ return this ->find_and_load_config_file_for_input (file_path.c_str ());
89
+ },
90
+ make_canonicalize_path_error_handlers (
91
+ [](std::string&& message) -> configuration_or_error {
92
+ return configuration_or_error (std::move (message));
93
+ }),
94
+ make_read_file_error_handlers ([](std::string&& message) {
95
+ return configuration_or_error (std::move (message));
96
+ }),
97
+ [](boost::leaf::e_errno error) {
98
+ return configuration_or_error (std::strerror (error.value ));
99
+ },
100
+ []() {
101
+ QLJS_ASSERT (false );
102
+ return configuration_or_error (" unknown error" );
103
+ });
69
104
}
70
105
71
106
configuration_or_error configuration_loader::load_for_file (
@@ -128,32 +163,15 @@ boost::leaf::result<configuration*> configuration_loader::load_config_file(
128
163
QLJS_WARNING_PUSH
129
164
QLJS_WARNING_IGNORE_GCC (" -Wuseless-cast" )
130
165
131
- configuration_or_error
166
+ boost::leaf::result<configuration*>
132
167
configuration_loader::find_and_load_config_file_for_input (
133
168
const char * input_path) {
134
- return boost::leaf::try_handle_all (
135
- [&]() -> boost::leaf::result<configuration_or_error> {
136
- boost::leaf::result<canonical_path_result> parent_directory =
137
- this ->get_parent_directory (input_path);
138
- if (!parent_directory) return parent_directory.error ();
139
- return this ->find_and_load_config_file_in_directory_and_ancestors (
140
- std::move (*parent_directory).canonical (),
141
- /* input_path=*/ input_path);
142
- },
143
- make_canonicalize_path_error_handlers (
144
- [](std::string&& message) -> configuration_or_error {
145
- return configuration_or_error (std::move (message));
146
- }),
147
- make_read_file_error_handlers ([](std::string&& message) {
148
- return configuration_or_error (std::move (message));
149
- }),
150
- [](boost::leaf::e_errno error) {
151
- return configuration_or_error (std::strerror (error.value ));
152
- },
153
- []() {
154
- QLJS_ASSERT (false );
155
- return configuration_or_error (" unknown error" );
156
- });
169
+ boost::leaf::result<canonical_path_result> parent_directory =
170
+ this ->get_parent_directory (input_path);
171
+ if (!parent_directory) return parent_directory.error ();
172
+ return this ->find_and_load_config_file_in_directory_and_ancestors (
173
+ std::move (*parent_directory).canonical (),
174
+ /* input_path=*/ input_path);
157
175
}
158
176
159
177
boost::leaf::result<configuration*>
0 commit comments