Skip to content

get(String) InputStream throws generic IOException("error") instead of using throwStatusError #1013

Description

@adrianovalente

Hello 👋

I'm using jsch to download files via SFTP using the get(String) function that returns an InputStream. Taking a look on the code, I discovered that if the server returns a non-EOF status code during a read, we will throw a generic IOException with the message "error", which makes it very hard to debug:

com.jcraft.jsch.ChannelSftp$2 read "ChannelSftp.java" 1427
java.io.InputStream readNBytes "InputStream.java" 412
java.io.InputStream readAllBytes "InputStream.java" 349

(Full stack trace from our Clojure application below.)

Looking at the source code, I discovered that there used to be a call to throwStatusError, which would return a richer exception data including the status enum, but this is commented out and taking a look at past commits I couldn't find the reason why.

if (type == SSH_FXP_STATUS) {
fill(buf, rest_length);
int i = buf.getInt();
rest_length = 0;
if (i == SSH_FX_EOF) {
close();
return -1;
}
// throwStatusError(buf, i);
throw new IOException("error");
}

I am currently debugging some intermitend server exceptios on my application, and having this code commented makes it impossible to know whether the failure was SSH_FX_NO_SUCH_FILE, SSH_FX_PERMISSION_DENIED, SSH_FX_FAILURE, or something else.

Do you know if this commented code is intentional, or is it just a behavior inherited from the original jcraft/jsch code?

Full stack trace (Clojure)
[com.jcraft.jsch.ChannelSftp$2 read "ChannelSftp.java" 1427]
[java.io.InputStream readNBytes "InputStream.java" 412]
[java.io.InputStream readAllBytes "InputStream.java" 349]
[common_ftp.components.sftp$fn__21345$get_file__21350$fn__21351$fn__21356 invoke "sftp.clj" 189]
[common_ftp.components.sftp$ignoring_missing_file invokeStatic "sftp.clj" 162]
[common_ftp.components.sftp$ignoring_missing_file invoke "sftp.clj" 157]
[common_ftp.components.sftp$fn__21345$get_file__21350$fn__21351 invoke "sftp.clj" 186]
[common_ftp.components.sftp$fn__21345$get_file__21350 invoke "sftp.clj" 182]
...

Exception cause: "error"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions