Skip to content

Commit 4ea6e12

Browse files
committed
Remove error-swallowing try/except blocks from examples; let exceptions propagate naturally. HLC example uses try/finally to ensure landing on failure.
1 parent 3436e46 commit 4ea6e12

5 files changed

Lines changed: 17 additions & 43 deletions

File tree

examples/app_channel.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ async def main() -> None:
120120
print("\n" + "-" * 60)
121121
print("All tests passed! ✓")
122122

123-
except ValueError as e:
124-
print(f"\nError: {e}")
125123
except KeyboardInterrupt:
126124
print("\n" + "-" * 60)
127125
print("Interrupted by user")

examples/high_level_commander.py

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,45 +45,31 @@ async def main() -> None:
4545

4646
hlc = cf.high_level_commander()
4747

48-
print("Taking off...")
4948
try:
49+
print("Taking off...")
5050
await hlc.take_off(0.5, None, 2.0, None)
5151
await asyncio.sleep(2.0)
52-
except Exception as e:
53-
print(f"Take-off failed: {e}")
5452

55-
print("Going to first position...")
56-
try:
53+
print("Going to first position...")
5754
await hlc.go_to(0.0, 0.5, 0.5, 0.0, 2.0, False, False, None)
5855
await asyncio.sleep(2.0)
59-
except Exception as e:
60-
print(f"Go-to failed: {e}")
6156

62-
print("Going to second position...")
63-
try:
57+
print("Going to second position...")
6458
await hlc.go_to(-0.25, 0.0, 0.5, 0.0, 2.0, False, False, None)
6559
await asyncio.sleep(2.0)
66-
except Exception as e:
67-
print(f"Go-to failed: {e}")
6860

69-
print("Moving in a spiral...")
70-
try:
61+
print("Moving in a spiral...")
7162
await hlc.spiral(-math.pi * 2.0, 0.5, 0.5, 0.0, 2.0, True, True, None)
7263
await asyncio.sleep(2.0)
73-
except Exception as e:
74-
print(f"Spiral failed: {e}")
75-
76-
print("Landing...")
77-
try:
64+
finally:
65+
print("Landing...")
7866
await hlc.land(0.0, None, 2.0, None)
7967
await asyncio.sleep(2.0)
80-
except Exception as e:
81-
print(f"Landing failed: {e}")
8268

83-
await hlc.stop(None)
84-
print("Done")
69+
await hlc.stop(None)
70+
print("Done")
8571

86-
await cf.disconnect()
72+
await cf.disconnect()
8773

8874

8975
if __name__ == "__main__":

examples/lighthouse_persist.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,6 @@ async def main() -> None:
121121
except KeyboardInterrupt:
122122
print("\n\nInterrupted by user")
123123

124-
except Exception as e:
125-
print(f"\n✗ Error: {e}")
126-
127124
finally:
128125
print("\nDisconnecting...")
129126
await cf.disconnect()

examples/log.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ async def main() -> None:
8080
)
8181
except KeyboardInterrupt:
8282
print("\nStopping...")
83-
except Exception as e:
84-
print(f"\nError: {e}")
8583
finally:
8684
await log_stream.stop()
8785
await cf.disconnect()

examples/toc_cache.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,17 @@ async def main() -> int:
101101

102102
start_time = time.time()
103103

104-
try:
105-
cf = await Crazyflie.connect_from_uri(context, args.uri, toc_cache=cache)
106-
connect_time = time.time() - start_time
107-
connection_times.append(connect_time)
104+
cf = await Crazyflie.connect_from_uri(context, args.uri, toc_cache=cache)
105+
connect_time = time.time() - start_time
106+
connection_times.append(connect_time)
108107

109-
print(f"{connect_time:.3f}s")
108+
print(f"{connect_time:.3f}s")
110109

111-
await cf.disconnect()
110+
await cf.disconnect()
112111

113-
# Brief pause between connections
114-
if attempt < args.connections:
115-
await asyncio.sleep(0.5)
116-
117-
except Exception as e:
118-
print(f"FAILED - {e}")
119-
return 1
112+
# Brief pause between connections
113+
if attempt < args.connections:
114+
await asyncio.sleep(0.5)
120115

121116
# Print summary
122117
print(f"\nConnection times: {', '.join(f'{t:.3f}s' for t in connection_times)}")

0 commit comments

Comments
 (0)