slimta / python-slimta

Python libraries to send, receive, and queue email.
https://slimta.org/
MIT License
171 stars 43 forks source link

Exception handling in pipe relay #147

Closed gpatel-fr closed 5 years ago

gpatel-fr commented 5 years ago

Hello when having an error in the handling of a pipe relay, I get

Traceback (most recent call last):
  File "src/gevent/greenlet.py", line 766, in gevent._greenlet.Greenlet.run
  File "/opt/anaconda/lib/python3.7/site-packages/python_slimta-4.0.7-py3.7.egg/slimta/queue/__init__.py", line 390, in _attempt
    results = self.relay._attempt(envelope, attempts)
  File "/opt/anaconda/lib/python3.7/site-packages/python_slimta-4.0.7-py3.7.egg/slimta/relay/__init__.py", line 94, in _attempt
    return self.attempt(envelope, attempts)
  File "/opt/anaconda/lib/python3.7/site-packages/python_slimta-4.0.7-py3.7.egg/slimta/relay/pipe.py", line 180, in attempt
    return self._try_pipe_all_rcpts(envelope)
  File "/opt/anaconda/lib/python3.7/site-packages/python_slimta-4.0.7-py3.7.egg/slimta/relay/pipe.py", line 127, in _try_pipe_all_rcpts
    results[rcpt] = self._exec_process(args, stdin)
  File "/opt/anaconda/lib/python3.7/site-packages/python_slimta-4.0.7-py3.7.egg/slimta/relay/pipe.py", line 112, in _exec_process
    self.raise_error(p.returncode, stdout, stderr)
  File "/opt/anaconda/lib/python3.7/site-packages/python_slimta-4.0.7-py3.7.egg/slimta/relay/pipe.py", line 171, in raise_error
    if self._permanent_error_pattern.match(error_msg):
TypeError: cannot use a string pattern on a bytes-like object

changing a bit pipe.py make it behave more:

--- pipe.py.ori 2019-03-10 15:20:35.683277832 +0000
+++ pipe.py 2019-03-17 23:17:23.387128279 +0000
@@ -109,7 +109,7 @@
         log.exit(p)
         if p.returncode != 0:
             try:
-                self.raise_error(p.returncode, stdout, stderr)
+                self.raise_error(p.returncode, stdout.decode('utf-8'), stderr.decode('utf-8'))
             except (PermanentRelayError, TransientRelayError) as exc:
                 return exc
         return None

I tried to set utf-8 in the subprocess call but it's was not very effective since there seem to be other parts in the code that use bytes objects :-/

icgood commented 5 years ago

@gpatel-fr thanks for the fix