[Tutor] properly propagate problems

ingo janssen ingoogni at gmail.com
Sat Mar 23 06:04:19 EDT 2019


One thing I often struggle with is how to deal with exceptions, 
especially when I have a chain of functions that use each others output 
and/or long running processes. As the answer will probably be "it 
depends" take for example this program flow:

open a file and read into BytesIO buffer
get a FTP connection from pool
send buffer to plantuml.jar in memory FTP server
render file to image
get image from FTP server
push the image onto CherryPy bus
push (SSE) the image to web browser

def read_file(input_file):
     try:
         with open(input_file, 'rb') as f:
             buffer = io.BytesIO(f.read())
     except FileNotFoundError as e:
         print(e)
         ....
     return buffer

assume the file is not found, I cannot just kill the whole process. 
Catching the exception is one thing, but how to deal with it properly, I 
have to inform the client somehow what went wrong.

In this case I could push the error message into the returned buffer and 
just go from there and the image will show the message.

I could also bypass the whole process somehow and push the error message 
directly on the CherryPy bus.

What is wisdom, are there some general rules to follow in such cases

ingo


More information about the Tutor mailing list