Skip to content

Commit b68d590

Browse files
Make split_string check&throw instead of assert return value
The 2-string version of split_string previously asserted that the split would result in the right number of substrings. That made it not very useful for parsing user input, as using it would require parsing the string before passing it to split_string.
1 parent d314770 commit b68d590

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/util/string_utils.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Author: Daniel Poetzl
77
\*******************************************************************/
88

99
#include "string_utils.h"
10+
#include "exception_utils.h"
1011
#include "invariant.h"
1112

1213
#include <cassert>
@@ -109,7 +110,14 @@ void split_string(
109110
std::vector<std::string> result;
110111

111112
split_string(s, delim, result, strip);
112-
CHECK_RETURN(result.size() == 2);
113+
if(result.size() != 2)
114+
{
115+
throw deserialization_exceptiont{"expected string `" + s +
116+
"' to contain two substrings "
117+
"delimited by " +
118+
delim + " but has " +
119+
std::to_string(result.size())};
120+
}
113121

114122
left=result[0];
115123
right=result[1];

0 commit comments

Comments
 (0)