[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Better exception when calling set_conf() with the wrong type
commit 9b4a7fe6b720665eae7fdf5e378b9dbcab5ebc4a
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Fri Mar 23 13:37:05 2018 -0700
Better exception when calling set_conf() with the wrong type
When calling set_conf() with other types, say an integer value, we failed
internally with...
======================================================================
ERROR: test_transition_to_relay
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/atagar/Desktop/stem/test/require.py", line 58, in wrapped
return func(self, *args, **kwargs)
File "/home/atagar/Desktop/stem/test/require.py", line 58, in wrapped
return func(self, *args, **kwargs)
File "/home/atagar/Desktop/stem/test/integ/control/controller.py", line 1411, in test_transition_to_relay
controller.set_conf('OrPort', test.runner.ORPORT)
File "/home/atagar/Desktop/stem/stem/control.py", line 2332, in set_conf
self.set_options({param: value}, False)
File "/home/atagar/Desktop/stem/stem/control.py", line 2395, in set_options
query_comp.extend(['%s="%s"' % (param, val.strip()) for val in value])
TypeError: 'int' object is not iterable
This is porbably a reasonably common mistake so providing a better response...
======================================================================
ERROR: test_transition_to_relay
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/atagar/Desktop/stem/test/require.py", line 58, in wrapped
return func(self, *args, **kwargs)
File "/home/atagar/Desktop/stem/test/require.py", line 58, in wrapped
return func(self, *args, **kwargs)
File "/home/atagar/Desktop/stem/test/integ/control/controller.py", line 1411, in test_transition_to_relay
controller.set_conf('OrPort', test.runner.ORPORT)
File "/home/atagar/Desktop/stem/stem/control.py", line 2332, in set_conf
self.set_options({param: value}, False)
File "/home/atagar/Desktop/stem/stem/control.py", line 2399, in set_options
raise ValueError("Cannot set %s to %s since the value was a %s but we only accept strings" % (param, value, type(value).__name__))
ValueError: Cannot set OrPort to 1113 since the value was a int but we only accept strings
---
stem/control.py | 6 ++++--
test/integ/control/controller.py | 2 +-
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/stem/control.py b/stem/control.py
index 5ccc318f..8d25064b 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -2391,10 +2391,12 @@ class Controller(BaseController):
for param, value in params:
if isinstance(value, str):
query_comp.append('%s="%s"' % (param, value.strip()))
- elif value:
+ elif isinstance(value, collections.Iterable):
query_comp.extend(['%s="%s"' % (param, val.strip()) for val in value])
- else:
+ elif not value:
query_comp.append(param)
+ else:
+ raise ValueError('Cannot set %s to %s since the value was a %s but we only accept strings' % (param, value, type(value).__name__))
query = ' '.join(query_comp)
response = self.msg(query)
diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py
index 8042e858..5f823eea 100644
--- a/test/integ/control/controller.py
+++ b/test/integ/control/controller.py
@@ -1408,7 +1408,7 @@ class TestController(unittest.TestCase):
controller.reset_conf('OrPort', 'DisableNetwork')
self.assertEqual(None, controller.get_conf('OrPort'))
finally:
- controller.set_conf('OrPort', test.runner.ORPORT)
+ controller.set_conf('OrPort', str(test.runner.ORPORT))
def _get_router_status_entry(self, controller):
"""
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits