openssh_sftp_protocol_error/response_error.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
use std::fmt;
use serde::Deserialize;
use vec_strings::TwoStrs;
#[derive(Debug, Copy, Clone)]
#[non_exhaustive]
pub enum ErrorCode {
/// is returned when a reference is made to a file which should exist
/// but doesn't.
NoSuchFile,
/// Returned when the authenticated user does not have sufficient
/// permissions to perform the operation.
PermDenied,
/// A generic catch-all error message.
///
/// It should be returned if an error occurs for which there is no more
/// specific error code defined.
Failure,
/// May be returned if a badly formatted packet or protocol
/// incompatibility is detected.
///
/// If the handle is opened read only, but write flag is required,
/// then `BadMessage` might be returned, vice versa.
BadMessage,
/// Indicates that an attempt was made to perform an operation which
/// is not supported for the server.
OpUnsupported,
/// Unknown error code
Unknown,
}
#[derive(Clone, Deserialize)]
pub struct ErrMsg(TwoStrs);
impl ErrMsg {
/// Returns (err_message, language_tag).
///
/// Language tag is defined according to specification [RFC-1766].
///
/// It can be parsed by
/// [pyfisch/rust-language-tags](https://github.com/pyfisch/rust-language-tags)
/// according to
/// [this issue](https://github.com/pyfisch/rust-language-tags/issues/39).
pub fn get(&self) -> (&str, &str) {
self.0.get()
}
}
impl fmt::Display for ErrMsg {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let (err_msg, language_tag) = self.get();
write!(
f,
"Err Message: {}, Language Tag: {}",
err_msg, language_tag
)
}
}
impl fmt::Debug for ErrMsg {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}