@@ -47,6 +47,10 @@ class ServerError(Error):
47
47
pass
48
48
49
49
50
+ class InteractiveCommandError (Error ):
51
+ pass
52
+
53
+
50
54
class ClientSession (ApplicationSession ):
51
55
"""The ClientSession encapsulates all the actions a Client can Invoke on
52
56
the coordinator."""
@@ -842,14 +846,17 @@ async def _console(self, place, target, timeout, *, logfile=None, loop=False, li
842
846
raise
843
847
if p .returncode :
844
848
print ("connection lost" , file = sys .stderr )
845
- return False
846
- return True
849
+ return p .returncode
847
850
848
851
async def console (self , place , target ):
849
852
while True :
850
853
res = await self ._console (place , target , 10.0 , logfile = self .args .logfile ,
851
854
loop = self .args .loop , listen_only = self .args .listenonly )
852
- if res or not self .args .loop :
855
+ if res :
856
+ exc = InteractiveCommandError ("microcom error" )
857
+ exc .exitcode = res
858
+ raise exc
859
+ if not self .args .loop :
853
860
break
854
861
await asyncio .sleep (1.0 )
855
862
console .needs_target = True
@@ -1033,20 +1040,28 @@ def ssh(self):
1033
1040
drv = self ._get_ssh ()
1034
1041
1035
1042
res = drv .interact (self .args .leftover )
1036
- if res == 255 :
1037
- print ( "connection lost (SSH error)" , file = sys . stderr )
1038
- elif res :
1039
- print ( f"connection lost (remote exit code { res } )" , file = sys . stderr )
1043
+ if res :
1044
+ exc = InteractiveCommandError ( "ssh error" )
1045
+ exc . exitcode = res
1046
+ raise exc
1040
1047
1041
1048
def scp (self ):
1042
1049
drv = self ._get_ssh ()
1043
1050
1044
- drv .scp (src = self .args .src , dst = self .args .dst )
1051
+ res = drv .scp (src = self .args .src , dst = self .args .dst )
1052
+ if res :
1053
+ exc = InteractiveCommandError ("scp error" )
1054
+ exc .exitcode = res
1055
+ raise exc
1045
1056
1046
1057
def rsync (self ):
1047
1058
drv = self ._get_ssh ()
1048
1059
1049
- drv .rsync (src = self .args .src , dst = self .args .dst , extra = self .args .leftover )
1060
+ res = drv .rsync (src = self .args .src , dst = self .args .dst , extra = self .args .leftover )
1061
+ if res :
1062
+ exc = InteractiveCommandError ("rsync error" )
1063
+ exc .exitcode = res
1064
+ raise exc
1050
1065
1051
1066
def sshfs (self ):
1052
1067
drv = self ._get_ssh ()
@@ -1084,7 +1099,9 @@ def telnet(self):
1084
1099
args = ['telnet' , str (ip )]
1085
1100
res = subprocess .call (args )
1086
1101
if res :
1087
- print ("connection lost" , file = sys .stderr )
1102
+ exc = InteractiveCommandError ("telnet error" )
1103
+ exc .exitcode = res
1104
+ raise exc
1088
1105
1089
1106
def video (self ):
1090
1107
place = self .get_acquired_place ()
@@ -1115,14 +1132,22 @@ def video(self):
1115
1132
mark = '*' if default == name else ' '
1116
1133
print (f"{ mark } { name :<10s} { caps :s} " )
1117
1134
else :
1118
- drv .stream (quality , controls = controls )
1135
+ res = drv .stream (quality , controls = controls )
1136
+ if res :
1137
+ exc = InteractiveCommandError ("gst-launch-1.0 error" )
1138
+ exc .exitcode = res
1139
+ raise exc
1119
1140
1120
1141
def audio (self ):
1121
1142
place = self .get_acquired_place ()
1122
1143
target = self ._get_target (place )
1123
1144
name = self .args .name
1124
1145
drv = self ._get_driver_or_new (target , "USBAudioInputDriver" , name = name )
1125
- drv .play ()
1146
+ res = drv .play ()
1147
+ if res :
1148
+ exc = InteractiveCommandError ("gst-launch-1.0 error" )
1149
+ exc .exitcode = res
1150
+ raise exc
1126
1151
1127
1152
def _get_tmc (self ):
1128
1153
place = self .get_acquired_place ()
@@ -1864,6 +1889,10 @@ def main():
1864
1889
except ConnectionError as e :
1865
1890
print (f"Could not connect to coordinator: { e } " , file = sys .stderr )
1866
1891
exitcode = 1
1892
+ except InteractiveCommandError as e :
1893
+ if args .debug :
1894
+ traceback .print_exc (file = sys .stderr )
1895
+ exitcode = e .exitcode
1867
1896
except Error as e :
1868
1897
if args .debug :
1869
1898
traceback .print_exc (file = sys .stderr )
0 commit comments