#![forbid(unsafe_code)]
use std::{io, num::TryFromIntError, process::ExitStatus};
pub use awaitable_error::Error as AwaitableError;
pub use openssh_sftp_protocol_error::{
ErrMsg as SftpErrMsg, ErrorCode as SftpErrorKind, UnixTimeStampError,
};
pub use ssh_format_error::Error as SshFormatError;
use thiserror::Error as ThisError;
#[non_exhaustive]
#[derive(Debug, ThisError)]
pub enum Error {
#[error("Server does not support sftp protocol v3: It only support sftp protocol newer than {version}.")]
UnsupportedSftpProtocol {
version: u32,
},
#[error("sftp server returned hello message of length {len}, which is longer than 4096.")]
SftpServerHelloMsgTooLong {
len: u32,
},
#[error("sftp-server run on remote server failed: {0}.")]
SftpServerFailure(ExitStatus),
#[error("Background task failed: {0}.")]
BackgroundTaskFailure(&'static &'static str),
#[error("Unsupported extension {0}.")]
UnsupportedExtension(&'static &'static str),
#[error("IO Error (Excluding `io::ErrorKind::WouldBlock`): {0}.")]
IOError(#[from] io::Error),
#[error("Failed to serialize/deserialize the message: {0}.")]
FormatError(#[from] SshFormatError),
#[error("Error when waiting for response: {0}.")]
AwaitableError(#[from] AwaitableError),
#[error("Sftp protocol can only send and receive at most u32::MAX data in one request.")]
BufferTooLong(#[from] TryFromIntError),
#[error("The response id {response_id} is invalid.")]
InvalidResponseId {
response_id: u32,
},
#[error(transparent)]
RecursiveErrors(Box<RecursiveError>),
#[error(transparent)]
RecursiveErrors3(Box<RecursiveError3>),
#[error("Sftp server reported error kind {0:#?}, msg: {1}")]
SftpError(SftpErrorKind, SftpErrMsg),
#[error("Response from sftp server is invalid: {0}")]
InvalidResponse(
&'static &'static str,
),
#[error("Handle returned by server is longer than the limit 256 bytes specified in sftp v3")]
HandleTooLong,
#[error("Failed to join tokio task")]
TaskJoinError(#[from] tokio::task::JoinError),
#[cfg(feature = "openssh")]
#[error("Failed to create sftp from session: {0}")]
RemoteChildSpawnError(#[from] openssh::Error),
}
#[derive(Debug, ThisError)]
#[error("OriginalError: {original_error}, curr err raised when cleaning up: {occuring_error}.")]
pub struct RecursiveError {
pub original_error: Error,
#[source]
pub occuring_error: Error,
}
#[derive(Debug, ThisError)]
#[error("err1: {err1}, err2: {err2}, err3: {err3}.")]
pub struct RecursiveError3 {
pub err1: Error,
pub err2: Error,
#[source]
pub err3: Error,
}