Skip to content

Commit 7ba15a3

Browse files
committed
refactor: consolidate error handling by replacing InternalError with Errors.hpp
1 parent 57bca2e commit 7ba15a3

File tree

9 files changed

+33
-45
lines changed

9 files changed

+33
-45
lines changed

cucumber_cpp/library/Application.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "cucumber_cpp/library/Application.hpp"
22
#include "cucumber_cpp/library/Context.hpp"
3-
#include "cucumber_cpp/library/InternalError.hpp"
3+
#include "cucumber_cpp/library/Errors.hpp"
44
#include "cucumber_cpp/library/StepRegistry.hpp"
55
#include "cucumber_cpp/library/cucumber_expression/Errors.hpp"
66
#include "cucumber_cpp/library/engine/ContextManager.hpp"
@@ -21,7 +21,6 @@
2121
#include <algorithm>
2222
#include <exception>
2323
#include <filesystem>
24-
#include <format>
2524
#include <functional>
2625
#include <iostream>
2726
#include <iterator>

cucumber_cpp/library/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ add_library(cucumber_cpp.library STATIC ${CCR_EXCLUDE_FROM_ALL})
55
target_sources(cucumber_cpp.library PRIVATE
66
Application.cpp
77
Application.hpp
8-
BodyMacro.hpp
98
Body.hpp
9+
BodyMacro.hpp
1010
Context.hpp
11+
Errors.hpp
1112
HookRegistry.cpp
1213
HookRegistry.hpp
1314
Hooks.hpp
14-
InternalError.hpp
1515
Rtrim.cpp
1616
Rtrim.hpp
17-
Steps.hpp
1817
StepRegistry.cpp
1918
StepRegistry.hpp
19+
Steps.hpp
2020
TagExpression.cpp
2121
TagExpression.hpp
2222
TagsToSet.hpp

cucumber_cpp/library/Errors.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef LIBRARY_ERRORS_HPP
2+
#define LIBRARY_ERRORS_HPP
3+
4+
#include <stdexcept>
5+
6+
namespace cucumber_cpp::library
7+
{
8+
struct InternalError : std::runtime_error
9+
{
10+
using runtime_error::runtime_error;
11+
};
12+
13+
struct UnsupportedAsteriskError : std::runtime_error
14+
{
15+
using runtime_error::runtime_error;
16+
};
17+
}
18+
19+
#endif

cucumber_cpp/library/InternalError.hpp

Lines changed: 0 additions & 28 deletions
This file was deleted.

cucumber_cpp/library/TagExpression.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "cucumber_cpp/library/TagExpression.hpp"
2-
#include "cucumber_cpp/library/InternalError.hpp"
2+
#include "cucumber_cpp/library/Errors.hpp"
33
#include <functional>
44
#include <regex>
55
#include <set>

cucumber_cpp/library/engine/FeatureFactory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "cucumber/messages/scenario.hpp"
1414
#include "cucumber/messages/step.hpp"
1515
#include "cucumber/messages/tag.hpp"
16-
#include "cucumber_cpp/library/InternalError.hpp"
16+
#include "cucumber_cpp/library/Errors.hpp"
1717
#include "cucumber_cpp/library/StepRegistry.hpp"
1818
#include "cucumber_cpp/library/TagExpression.hpp"
1919
#include "cucumber_cpp/library/engine/FeatureInfo.hpp"

cucumber_cpp/library/engine/StringTo.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#ifndef ENGINE_STRINGTO_HPP
22
#define ENGINE_STRINGTO_HPP
33

4-
#include "cucumber_cpp/library/InternalError.hpp"
4+
#include "cucumber_cpp/library/Errors.hpp"
55
#include <algorithm>
66
#include <any>
77
#include <cctype>
8-
#include <source_location>
98
#include <sstream>
109
#include <string>
1110
#include <string_view>
@@ -15,18 +14,18 @@ namespace cucumber_cpp::library::engine
1514
{
1615

1716
template<class To>
18-
inline To StringTo(const std::string& s, std::source_location sourceLocation = std::source_location::current())
17+
inline To StringTo(const std::string& s)
1918
{
2019
std::istringstream stream{ s };
2120
To to;
2221
stream >> to;
2322
if (stream.fail())
24-
throw InternalError{ "Cannnot convert parameter \"" + s + "\"", sourceLocation };
23+
throw InternalError{ "Cannnot convert parameter \"" + s + "\"" };
2524
return to;
2625
}
2726

2827
template<>
29-
inline std::string StringTo<std::string>(const std::string& s, std::source_location /*sourceLocation*/)
28+
inline std::string StringTo<std::string>(const std::string& s)
3029
{
3130
return s;
3231
}
@@ -46,7 +45,7 @@ namespace cucumber_cpp::library::engine
4645
}
4746

4847
template<>
49-
inline bool StringTo<bool>(const std::string& s, std::source_location /*sourceLocation*/)
48+
inline bool StringTo<bool>(const std::string& s)
5049
{
5150
using details::iequals;
5251

cucumber_cpp/library/engine/Table.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#define ENGINE_TABLE_HPP
33

44
#include "cucumber_cpp/library/engine/StringTo.hpp"
5-
#include <source_location>
65
#include <string>
76
#include <utility>
87
#include <vector>
@@ -12,9 +11,9 @@ namespace cucumber_cpp::library::engine
1211
struct TableValue
1312
{
1413
template<class T>
15-
T As(std::source_location sourceLocation = std::source_location::current()) const
14+
T As() const
1615
{
17-
return StringTo<T>(value, sourceLocation);
16+
return StringTo<T>(value);
1817
}
1918

2019
explicit TableValue(std::string value)

cucumber_cpp/library/engine/test/TestStringTo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "cucumber_cpp/library/InternalError.hpp"
1+
#include "cucumber_cpp/library/Errors.hpp"
22
#include "cucumber_cpp/library/engine/StringTo.hpp"
33
#include "gmock/gmock.h"
44
#include "gtest/gtest.h"

0 commit comments

Comments
 (0)