From a6b4c9c56a3e0752137f615a6496814daa9e6a00 Mon Sep 17 00:00:00 2001 From: Goffi Date: Fri, 12 Jul 2019 08:55:41 +0200 Subject: [PATCH] jp (blog/edit): fail and show error message if --preview is not working --- sat_frontends/jp/cmd_blog.py | 38 ++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/sat_frontends/jp/cmd_blog.py b/sat_frontends/jp/cmd_blog.py index ee7cbc4c..64e959fb 100644 --- a/sat_frontends/jp/cmd_blog.py +++ b/sat_frontends/jp/cmd_blog.py @@ -514,23 +514,27 @@ class Edit(base.CommandBase, BlogPublishCommon, common.BaseEdit): # do we need a preview ? if self.args.preview: self.disp(u"Preview requested, launching it", 1) - # we redirect outputs to /dev/null to avoid console pollution in editor - # if user wants to see messages, (s)he can call "blog preview" directly - DEVNULL = open(os.devnull, "wb") - subprocess.Popen( - [ - sys.argv[0], - "blog", - "preview", - "--inotify", - "true", - "-p", - self.profile, - content_file_path, - ], - stdout=DEVNULL, - stderr=subprocess.STDOUT, - ) + # we redirect stderr to stdout and capture output to avoid console pollution + # in editor. + # If user wants to see messages, (s)he can call "blog preview" directly + try: + subprocess.check_output( + [ + sys.argv[0], + "blog", + "preview", + "--inotify", + "true", + "-p", + self.profile, + content_file_path, + ], + stderr=subprocess.STDOUT, + ) + except Exception as e: + self.disp(u"Can't show preview: {msg}".format( + msg=e.output.decode('utf-8'), err=True)) + sys.exit(e.returncode) # we launch editor self.runEditor(