Skip to content

Commit 1e0e8bc

Browse files
committed
catch a CalledProcessError and decode stderr
1 parent b31f93c commit 1e0e8bc

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

pybricksdev/cli/__init__.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import contextlib
99
import logging
1010
import os
11+
import subprocess
1112
import sys
1213
from abc import ABC, abstractmethod
1314
from enum import IntEnum
@@ -327,11 +328,10 @@ async def reconnect_hub():
327328
case _:
328329
return
329330

330-
except SyntaxError as e:
331+
except subprocess.CalledProcessError as e :
331332
print()
332333
print("A syntax error occurred while parsing your program:")
333-
print(e)
334-
print()
334+
print(e.stderr.decode())
335335

336336
except HubPowerButtonPressedError:
337337
# This means the user pressed the button on the hub to re-start the
@@ -416,11 +416,10 @@ def is_pybricks_usb(dev):
416416
if args.stay_connected:
417417
await self.stay_connected_menu(hub, args)
418418

419-
except SyntaxError as e:
419+
except subprocess.CalledProcessError as e:
420420
print()
421421
print("A syntax error occurred while parsing your program:")
422-
print(e)
423-
print()
422+
print(e.stderr.decode())
424423
if args.stay_connected:
425424
await self.stay_connected_menu(hub, args)
426425

0 commit comments

Comments
 (0)