Skip to content

Commit 730644b

Browse files
committed
more consistent error handling
1 parent ea839c0 commit 730644b

5 files changed

Lines changed: 27 additions & 21 deletions

File tree

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ DTLMod (0.2) November 11, 2025
2323
- Make metadata export configurable at stream level.
2424
- Have a simpler version of Engine::put() that automatically uses the
2525
local size of the Variable.
26+
- Stream::remove_variable now throws an UnknownVariableException rather
27+
than returning a bool
2628

2729
----------------------------------------------------------------------------
2830

include/dtlmod/Stream.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ class Stream : public std::enable_shared_from_this<Stream> {
166166

167167
/// @brief Remove a Variable of the list of variables known by the Stream.
168168
/// @param name The name of the variable to remove.
169-
/// @return A boolean indicating if the Variable has been successfully removed or not.
170-
bool remove_variable(const std::string& name);
169+
void remove_variable(const std::string& name);
171170
};
172171

173172
} // namespace dtlmod

src/Stream.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,14 +294,13 @@ std::shared_ptr<Variable> Stream::inquire_variable(const std::string& name) cons
294294
}
295295
}
296296

297-
bool Stream::remove_variable(const std::string& name)
297+
void Stream::remove_variable(const std::string& name)
298298
{
299299
auto var = variables_.find(name);
300-
if (var != variables_.end()) {
300+
if (var != variables_.end())
301301
variables_.erase(var);
302-
return true;
303-
} else
304-
return false;
302+
else
303+
throw UnknownVariableException(XBT_THROW_POINT, name);
305304
}
306305

307306
} // namespace dtlmod

test/dtl_variable.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ TEST_F(DTLVariableTest, DefineVariable)
5757
ASSERT_TRUE(var3D->get_name() == "var3D");
5858
XBT_INFO("Check size: should be 64^3 times 8 as elements are double");
5959
ASSERT_DOUBLE_EQ(var3D->get_global_size(), 64 * 64 * 64 * 8);
60-
XBT_INFO("Remove variable named 'var3D'. It is known, should be true");
61-
ASSERT_DOUBLE_EQ(stream->remove_variable("var3D"), true);
62-
XBT_INFO("Remove variable named 'var2D'. It is unknown, should be false");
63-
ASSERT_DOUBLE_EQ(stream->remove_variable("var2D"), false);
60+
XBT_INFO("Remove variable named 'var3D'. It is known, should be fine");
61+
ASSERT_NO_THROW(stream->remove_variable("var3D"));
62+
XBT_INFO("Remove variable named 'var2D'. It is unknown, should fail");
63+
ASSERT_THROW(stream->remove_variable("var2D"), dtlmod::UnknownVariableException);
6464
XBT_INFO("Disconnect the actor from the DTL");
6565
ASSERT_NO_THROW(dtlmod::DTL::disconnect());
6666
});
@@ -200,10 +200,10 @@ TEST_F(DTLVariableTest, RemoveVariable)
200200
ASSERT_NO_THROW(stream = dtl->add_stream("Stream"));
201201
XBT_INFO("Create a scalar int variable");
202202
ASSERT_NO_THROW(var = stream->define_variable("var", sizeof(int)));
203-
XBT_INFO("Remove variable named 'var'. It is known, should be true");
204-
ASSERT_TRUE(stream->remove_variable("var"));
205-
XBT_INFO("Remove an unknown variable, which should return false");
206-
ASSERT_FALSE(stream->remove_variable("unknow_var"));
203+
XBT_INFO("Remove variable named 'var'. It is known, should be fine");
204+
ASSERT_NO_THROW(stream->remove_variable("var"));
205+
XBT_INFO("Remove an unknown variable, which should throw");
206+
ASSERT_THROW(stream->remove_variable("unknow_var"), dtlmod::UnknownVariableException);
207207
XBT_INFO("Disconnect the actor from the DTL");
208208
ASSERT_NO_THROW(dtlmod::DTL::disconnect());
209209
});

test/python/dtl_variable.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@ def define_variable():
3939
assert var3d.name == "var3d"
4040
this_actor.info("Check size: should be 64^3 times 8 as elements are double")
4141
assert var3d.global_size == (64 * 64 * 64 * 8)
42-
this_actor.info("Remove variable named 'var3d'. It is known, should be true")
43-
assert stream.remove_variable("var3d") == True
42+
this_actor.info("Remove variable named 'var3d'. It is known, should be fine")
43+
stream.remove_variable("var3d")
4444
this_actor.info("Remove variable named 'var2D'. It is unknown, should be false")
45-
assert stream.remove_variable("var2D") == False
45+
try:
46+
stream.remove_variable("var2D")
47+
except UnknownVariableException:
48+
pass
4649

4750
this_actor.info("Disconnect from the DTL")
4851
DTL.disconnect()
@@ -177,10 +180,13 @@ def remove_variable():
177180
stream = dtl.add_stream("Stream")
178181
this_actor.info("Create a scalar int variable")
179182
stream.define_variable("var", ctypes.sizeof(ctypes.c_int))
180-
this_actor.info("Remove variable named 'var'. It is known, should be true")
181-
assert stream.remove_variable("var") == True
183+
this_actor.info("Remove variable named 'var'. It is known, should be fine")
184+
stream.remove_variable("var")
182185
this_actor.info("Remove an unknown variable, which should return false")
183-
assert stream.remove_variable("unknow_var") == False
186+
try:
187+
stream.remove_variable("unknow_var")
188+
except UnknownVariableException:
189+
pass
184190
this_actor.info("Disconnect the actor from the DTL")
185191
DTL.disconnect()
186192

0 commit comments

Comments
 (0)