openssh_sftp_error/
lib.rs1#![forbid(unsafe_code)]
2
3use std::{io, num::TryFromIntError, process::ExitStatus};
4
5pub use awaitable_error::Error as AwaitableError;
6pub use openssh_sftp_protocol_error::{
7 ErrMsg as SftpErrMsg, ErrorCode as SftpErrorKind, UnixTimeStampError,
8};
9pub use ssh_format_error::Error as SshFormatError;
10use thiserror::Error as ThisError;
11
12#[non_exhaustive]
16#[derive(Debug, ThisError)]
17pub enum Error {
18 #[error("Server does not support sftp protocol v3: It only support sftp protocol newer than {version}.")]
20 UnsupportedSftpProtocol {
21 version: u32,
23 },
24
25 #[error("sftp server returned hello message of length {len}, which is longer than 4096.")]
27 SftpServerHelloMsgTooLong {
28 len: u32,
30 },
31
32 #[error("sftp-server run on remote server failed: {0}.")]
37 SftpServerFailure(ExitStatus),
38
39 #[error("Background task failed: {0}.")]
44 BackgroundTaskFailure(&'static &'static str),
45
46 #[error("Unsupported extension {0}.")]
51 UnsupportedExtension(&'static &'static str),
52
53 #[error("IO Error (Excluding `io::ErrorKind::WouldBlock`): {0}.")]
55 IOError(#[from] io::Error),
56
57 #[error("Failed to serialize/deserialize the message: {0}.")]
59 FormatError(#[from] SshFormatError),
60
61 #[error("Error when waiting for response: {0}.")]
63 AwaitableError(#[from] AwaitableError),
64
65 #[error("Sftp protocol can only send and receive at most u32::MAX data in one request.")]
67 BufferTooLong(#[from] TryFromIntError),
68
69 #[error("The response id {response_id} is invalid.")]
73 InvalidResponseId {
74 response_id: u32,
76 },
77
78 #[error(transparent)]
80 RecursiveErrors(Box<RecursiveError>),
81
82 #[error(transparent)]
84 RecursiveErrors3(Box<RecursiveError3>),
85
86 #[error("Sftp server reported error kind {0:#?}, msg: {1}")]
88 SftpError(SftpErrorKind, SftpErrMsg),
89
90 #[error("Response from sftp server is invalid: {0}")]
92 InvalidResponse(
93 &'static &'static str,
95 ),
96
97 #[error("Handle returned by server is longer than the limit 256 bytes specified in sftp v3")]
99 HandleTooLong,
100
101 #[error("Failed to join tokio task")]
103 TaskJoinError(#[from] tokio::task::JoinError),
104
105 #[cfg(feature = "openssh")]
106 #[error("Failed to create sftp from session: {0}")]
107 RemoteChildSpawnError(#[from] openssh::Error),
108}
109
110#[derive(Debug, ThisError)]
111#[error("OriginalError: {original_error}, curr err raised when cleaning up: {occuring_error}.")]
112pub struct RecursiveError {
113 pub original_error: Error,
115
116 #[source]
119 pub occuring_error: Error,
120}
121
122#[derive(Debug, ThisError)]
123#[error("err1: {err1}, err2: {err2}, err3: {err3}.")]
124pub struct RecursiveError3 {
125 pub err1: Error,
127
128 pub err2: Error,
130
131 #[source]
133 pub err3: Error,
134}