Skip to content

Commit f9991fd

Browse files
larskspeterbarker
authored andcommitted
raise ValueError if we are passed a bad value
Given a bad value, we were sometimes raising a bare Exception, sometimes raising a ValueError, and sometimes raising an APIError. This commit attempts to make things consistent by raising ValueError when that's what we mean. There is also a drive-by correction to the spelling of "Expecting".
1 parent bd3048a commit f9991fd

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

dronekit/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,7 +1957,7 @@ def home_location(self, pos):
19571957
"""
19581958

19591959
if not isinstance(pos, LocationGlobal):
1960-
raise Exception('Excepting home_location to be set to a LocationGlobal.')
1960+
raise ValueError('Expecting home_location to be set to a LocationGlobal.')
19611961

19621962
# Set cached home location.
19631963
self._home_location = copy.copy(pos)
@@ -2058,7 +2058,7 @@ def simple_goto(self, location, airspeed=None, groundspeed=None):
20582058
self.commands.wait_ready()
20592059
alt = location.alt - self.home_location.alt
20602060
else:
2061-
raise APIException('Expecting location to be LocationGlobal or LocationGlobalRelative.')
2061+
raise ValueError('Expecting location to be LocationGlobal or LocationGlobalRelative.')
20622062

20632063
self._master.mav.mission_item_send(0, 0, 0, frame,
20642064
mavutil.mavlink.MAV_CMD_NAV_WAYPOINT, 2, 0, 0,
@@ -2229,7 +2229,7 @@ def wait_ready(self, *types, **kwargs):
22292229
types = self._default_ready_attrs
22302230

22312231
if not all(isinstance(item, basestring) for item in types):
2232-
raise APIException('wait_ready expects one or more string arguments.')
2232+
raise ValueError('wait_ready expects one or more string arguments.')
22332233

22342234
# Wait for these attributes to have been set.
22352235
await = set(types)
@@ -2387,7 +2387,7 @@ def target_location(self,roi):
23872387
self.commands.wait_ready()
23882388
alt = roi.alt - self.home_location.alt
23892389
else:
2390-
raise APIException('Expecting location to be LocationGlobal or LocationGlobalRelative.')
2390+
raise ValueError('Expecting location to be LocationGlobal or LocationGlobalRelative.')
23912391

23922392
#set the ROI
23932393
msg = self._vehicle.message_factory.command_long_encode(

0 commit comments

Comments
 (0)