nylas / sync-engine

:incoming_envelope: IMAP/SMTP sync system with modern APIs
https://nylas.com/docs/platform
GNU Affero General Public License v3.0
3.5k stars 354 forks source link

Catch additional exceptions when parsing messages #158

Open thomasst opened 9 years ago

thomasst commented 9 years ago

Right now, https://github.com/nylas/sync-engine/blob/master/inbox/models/message.py#L188 only catches (mime.DecodingError, AttributeError, RuntimeError, TypeError). You might consider changing this to Exception, so any exception is caught.

Here's a traceback for uncaught re.error, which you're not catching currently:

Traceback (most recent call last):
          File "/home/ubuntu/inbox/inbox/util/concurrency.py", line 73, in wrapped
    return func(*args, **kwargs)
          File "/home/ubuntu/inbox/inbox/mailsync/backends/imap/generic.py", line 205, in _run_impl
    self.state = self.state_handlers[old_state]()
          File "/home/ubuntu/inbox/inbox/util/concurrency.py", line 73, in wrapped
    return func(*args, **kwargs)
          File "/home/ubuntu/inbox/inbox/mailsync/backends/imap/generic.py", line 266, in initial_sync
    self.initial_sync_impl(crispin_client)
          File "/home/ubuntu/inbox/inbox/mailsync/backends/gmail.py", line 109, in initial_sync_impl
    self.__download_queued_threads(crispin_client, download_stack)
          File "/home/ubuntu/inbox/inbox/mailsync/backends/gmail.py", line 298, in __download_queued_threads
    metadata.thrid, thread_uids)
         File "/home/ubuntu/inbox/inbox/mailsync/backends/gmail.py", line 332, in __download_thread
    crispin_client, crispin_client.selected_folder_name, uids)
          File "/home/ubuntu/inbox/inbox/mailsync/backends/gmail.py", line 260, in download_and_commit_uids
    raw_messages, self.create_message)
          File "/home/ubuntu/inbox/inbox/mailsync/backends/base.py", line 142, in create_db_objects
    uid = msg_create_fn(db_session, acc, folder, msg)
          File "/home/ubuntu/inbox/inbox/mailsync/backends/imap/generic.py", line 429, in create_message
    msg)
          File "/home/ubuntu/inbox/inbox/mailsync/backends/imap/common.py", line 260, in create_imap_message
    body_string=msg.body)
          File "/home/ubuntu/inbox/inbox/models/message.py", line 187, in create_from_synced
    parsed = mime.from_string(body_string)
          File "/usr/local/lib/python2.7/dist-packages/flanker/mime/create.py", line 82, in from_string
    return scanner.scan(string)
          File "/usr/local/lib/python2.7/dist-packages/flanker/mime/message/scanner.py", line 20, in scan
    tokens = tokenize(string)
          File "/usr/local/lib/python2.7/dist-packages/flanker/mime/message/scanner.py", line 396, in tokenize
    name, token = parsing.parse_header(m.group(_CTYPE))
          File "/usr/local/lib/python2.7/dist-packages/flanker/mime/message/headers/parsing.py", line 31, in parse_header
    return name, parse_header_value(name, encodedword.unfold(val))
          File "/usr/local/lib/python2.7/dist-packages/flanker/mime/message/headers/parsing.py", line 41, in parse_header_value
    val, params = parametrized.decode(val)
          File "/usr/local/lib/python2.7/dist-packages/flanker/mime/message/headers/parametrized.py", line 23, in decode
    return value, decode_parameters(rest)
          File "/usr/local/lib/python2.7/dist-packages/flanker/mime/message/headers/parametrized.py", line 67, in decode_parameters
    parameters = collect_parameters(string)
          File "/usr/local/lib/python2.7/dist-packages/flanker/mime/message/headers/parametrized.py", line 79, in collect_parameters
    p, rest = match_parameter(rest)
          File "/usr/local/lib/python2.7/dist-packages/flanker/mime/message/headers/parametrized.py", line 108, in match_parameter
    p, rest = match(rest)
          File "/usr/local/lib/python2.7/dist-packages/flanker/mime/message/headers/parametrized.py", line 125, in match_new
    match = newStyleParameter.match(rest)
        error: too much backtracking
grinich commented 8 years ago

@thomasst Do you have a message that can help us repo? We catch these errors using Sentry and strive to actually fix them. :)

grinich commented 8 years ago

:wave: :question: