From bbe37376761a3a36d903e9a60d689034a989cd51 Mon Sep 17 00:00:00 2001 From: schneefux Date: Tue, 30 Dec 2014 15:50:49 +0100 Subject: Better error handling in g2p module --- client/g2p.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'client') diff --git a/client/g2p.py b/client/g2p.py index c40e3a2..7b80226 100644 --- a/client/g2p.py +++ b/client/g2p.py @@ -39,19 +39,22 @@ class PhonetisaurusG2P(object): proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdoutdata, stderrdata = proc.communicate() - if proc.returncode != 0: - logger.warning("Command '%s' return with exit status %d", - ' '.join(cmd), proc.returncode) except OSError: logger.error("Error occured while executing command '%s'", ' '.join(cmd), exc_info=True) - stdoutdata, stderrdata = None, None - if stderrdata is not None: + raise + + if stderrdata: for line in stderrdata.splitlines(): message = line.strip() if message: logger.debug(message) + if proc.returncode != 0: + logger.error("Command '%s' return with exit status %d", + ' '.join(cmd), proc.returncode) + raise OSError("Command execution failed") + result = {} if stdoutdata is not None: for word, precision, pronounc in cls.PATTERN.findall(stdoutdata): -- cgit v1.3.1