Skip to content

Commit

Permalink
Check for herbstclient exit code
Browse files Browse the repository at this point in the history
This makes the HLWMInput() caller check that the exit code is 0.
Otherwise, an assertion and a backtrace is printed. Such a backtrace
would have been a more helpful error message in issue #21.
  • Loading branch information
t-wissmann committed Sep 28, 2022
1 parent e4c2e72 commit 0f78dcd
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions barpyrus/hlwm.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,19 @@ def handle_line(self,line):
if args[0] in self.hooks:
for cb in self.hooks[args[0]]:
cb(args[1:])
def __call__(self,args):

def __call__(self, args, check=True):
cmd = [ "herbstclient", "-n" ]
cmd += args;
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
proc.wait()
return proc.stdout.read().decode("utf-8")
def monitor_rect(hc, monitor = None):
exit_code = proc.wait()
stdout = proc.stdout.read().decode()
if check:
assert exit_code == 0, \
f'Error: command {args} exited with non-success code {exit_code} (and stdout "{stdout}")'
return stdout

def monitor_rect(hc, monitor=None):
if monitor == None:
if len(sys.argv) >= 2:
monitor = int(sys.argv[1])
Expand Down

0 comments on commit 0f78dcd

Please sign in to comment.