Skip to content

Commit f478f58

Browse files
committed
Refactor error handlers in load_for_file
Merge duplicated error handlers. This commit should not change behavior.
1 parent ae2b118 commit f478f58

File tree

1 file changed

+23
-37
lines changed

1 file changed

+23
-37
lines changed

src/configuration-loader.cpp

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -70,47 +70,33 @@ configuration_or_error configuration_loader::load_for_file(
7070

7171
configuration_or_error configuration_loader::load_for_file(
7272
const file_to_lint& file) {
73-
if (file.config_file) {
74-
return boost::leaf::try_handle_all(
75-
[&]() -> boost::leaf::result<configuration_or_error> {
73+
return boost::leaf::try_handle_all(
74+
[&]() -> boost::leaf::result<configuration_or_error> {
75+
if (file.config_file) {
7676
return this->load_config_file(file.config_file);
77-
},
78-
make_canonicalize_path_error_handlers(
79-
[](std::string&& message) -> configuration_or_error {
80-
return configuration_or_error(std::move(message));
81-
}),
82-
make_read_file_error_handlers(
83-
[](std::string&& message) -> configuration_or_error {
84-
return configuration_or_error(std::move(message));
85-
}),
86-
[]() {
87-
QLJS_ASSERT(false);
88-
return configuration_or_error("unknown error");
89-
});
90-
} else {
91-
if (file.path) {
92-
return this->find_and_load_config_file_for_input(file.path);
93-
} else {
94-
return boost::leaf::try_handle_all(
95-
[&]() -> boost::leaf::result<configuration_or_error> {
77+
} else {
78+
if (file.path) {
79+
return this->find_and_load_config_file_for_input(file.path);
80+
} else {
9681
return this->find_and_load_config_file_for_current_directory();
97-
},
98-
make_canonicalize_path_error_handlers(
99-
[](std::string&& message) -> configuration_or_error {
100-
return configuration_or_error(std::move(message));
101-
}),
102-
make_read_file_error_handlers([](std::string&& message) {
82+
}
83+
}
84+
},
85+
make_canonicalize_path_error_handlers(
86+
[](std::string&& message) -> configuration_or_error {
10387
return configuration_or_error(std::move(message));
10488
}),
105-
[](boost::leaf::e_errno error) {
106-
return configuration_or_error(std::strerror(error.value));
107-
},
108-
[]() {
109-
QLJS_ASSERT(false);
110-
return configuration_or_error("unknown error");
111-
});
112-
}
113-
}
89+
make_read_file_error_handlers(
90+
[](std::string&& message) -> configuration_or_error {
91+
return configuration_or_error(std::move(message));
92+
}),
93+
[](boost::leaf::e_errno error) {
94+
return configuration_or_error(std::strerror(error.value));
95+
},
96+
[]() {
97+
QLJS_ASSERT(false);
98+
return configuration_or_error("unknown error");
99+
});
114100
}
115101

116102
boost::leaf::result<configuration*> configuration_loader::load_config_file(

0 commit comments

Comments
 (0)