Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix unusued fout var in "finally" block in case of exception #28

Closed

Conversation

alekseydevel
Copy link

No description provided.

@rsichnyi
Copy link
Contributor

@tier2003

  1. as discussed, connection.path_io.open(real_path, mode=mode) will raise OSError actually
  2. unfortunatelly, stream.read(connection.block_size) and connection.path_io.write(fout, data) can raise OSError as well, but in these cases response code is not 421... So i assume you should expect error only on open and not on other two calls

@pohmelie
Copy link
Collaborator

@tier2003

  1. There is same behaviour in retr_worker.
  2. I think there is more straight and simple solution:
fout = None
try:
    ...
finally:
    if fout is not None:
        ...

@alekseydevel
Copy link
Author

@pohmelie ,

  1. fixed the exception type and made similar changes to retr_worker method.
  2. made not by "not None" checking in order to have more informational errors.
  3. I have some doubts about "download" test. The 451 is returned, but I think from the part that saves the file, not the downloading one.

@pohmelie
Copy link
Collaborator

Stream will not be closed if we fail on open, I think. None solution is better, I think… or I missed something.

@pohmelie
Copy link
Collaborator

Try-except is attractive, but it's not obvious. If it fails, it should be fail, I think.

@alekseydevel
Copy link
Author

Well, I`ve started the issue because I had problems with opening during file upload.
The try block had been failing and in finally I was receiving the fout reference of fout before assignment

@alekseydevel
Copy link
Author

well, if we don`t need exception mess at that place - maybe if else would be enough

@pohmelie
Copy link
Collaborator

@tier2003
I got your problem. And None solution is better, in my mind, cause less deep structure, and less try.
But probably you are right. It is time to think.

@rsichnyi
Copy link
Contributor

rsichnyi commented Nov 2, 2015

maybe combine both?

fout = None
try:
    fout = yield from connection.path_io.open(real_path, mode=mode)
    while True:
        data = yield from stream.read(connection.block_size)
        if not data:
            break
        yield from connection.path_io.write(fout, data)

except OSError:
    connection.response("451", "operation aborted")
else:
    connection.response("226", "data transfer done")
finally:
    stream.close()
    if fout is not None:
        yield from connection.path_io.close(fout)

@pohmelie
Copy link
Collaborator

pohmelie commented Nov 2, 2015

@rsichny
@tier2003
This is good theme to think. We should care about all path-io, socket, etc. operations, that can produce exception, not only this open. For the last code I can say, that path_io.close can raise OSError. That is why I'm in think of centralized error catching.

@pohmelie pohmelie mentioned this pull request Nov 5, 2015
@pohmelie pohmelie closed this in 6d147d7 Nov 5, 2015
@pohmelie
Copy link
Collaborator

pohmelie commented Nov 5, 2015

Discussion will continue at #31

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants