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

stream_file bangs on SFTPClient.OperationError #8

Closed
zoten opened this issue Apr 29, 2020 · 2 comments
Closed

stream_file bangs on SFTPClient.OperationError #8

zoten opened this issue Apr 29, 2020 · 2 comments

Comments

@zoten
Copy link

zoten commented Apr 29, 2020

Hi! First of all, thanks for the great work!
I bumped into an exception in a non-bang function running a simple download pipeline, when using code like

case SftpClient.stream_file(conn, path) do
  {:ok, data} -> do_something_with(data)
  {:error, reason} -> {:error, reason}
end
** (SFTPClient.OperationError) Operation failed: permission_denied
    (sftp_client) lib/sftp_client/operation_util.ex:37: SFTPClient.OperationUtil.may_bang!/1
    (elixir) lib/stream.ex:1392: anonymous fn/5 in Stream.resource/3
    (elixir) lib/enum.ex:3023: Enum.reverse/1
    (elixir) lib/enum.ex:2668: Enum.to_list/1
    (myapp) lib/worker.ex:433: Worker.download/2

Can't access the sftp at the moment, but the error is pretty clear

I'm using 1.3.5 but didn't see any related diff in last commits
Didn't dig into the problem yet, pretty noob in elixir, but will try to take a look (and in the meanwhile add some defensive try rescue :P )

@tlux
Copy link
Owner

tlux commented Apr 29, 2020

Thanks for your bug report. I'm going to take a look at it later or tomorrow.

@tlux
Copy link
Owner

tlux commented Apr 30, 2020

I'm afraid that the exception is raised when evaluating the stream in your do_something_with_data function.

To clear things up: stream_file just creates the stream but does not evaluate it until you call Enum.to_list/1 or Stream.run/1. In fact, stream_file and its brother stream_file! will only return an error or raise when you are trying to stream a non-regular file, such as a directory or symbolic link.

The general behavior is consistent with how File.stream!/1 handles streaming. I agree that it might be a bit misleading. We should probably think about deprecating the non-bang version in the long run.

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

No branches or pull requests

2 participants