Skip to main content

strop_remote/address/
error.rs

1//! Why a textual remote address was refused. Every variant is a pure
2//! admission failure; none implies a subprocess was ever started.
3
4/// Why a textual remote address was refused.
5#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
6pub enum AddressError {
7    #[error("remote locations use the form `ssh://[user@]host[:port]/absolute/path`")]
8    NotSshUri,
9    #[error(
10        "SSH locations cannot carry a password (`user:pass@`); authenticate with keys or an agent instead"
11    )]
12    PasswordInUri,
13    #[error("empty username before `@`")]
14    EmptyUser,
15    #[error("host is empty")]
16    EmptyHost,
17    #[error("port must be 1-65535 written in digits, e.g. `:2222`")]
18    InvalidPort,
19    #[error(
20        "refusing an option-shaped username/host (leading `-` or any `=`): SSH would read it as an option"
21    )]
22    OptionShapedEndpoint,
23    #[error("IPv6 hosts need brackets, e.g. `ssh://[2001:db8::1]:22/var/log/app.log`")]
24    UnbracketedIpv6,
25    #[error("bracketed IPv6 host is missing its closing `]`")]
26    UnclosedIpv6,
27    #[error("only `:port` may follow a bracketed IPv6 host")]
28    JunkAfterIpv6,
29    #[error("{literal:?} is not a valid IPv6 address")]
30    InvalidIpv6 { literal: String },
31    #[error("{literal:?} looks like an IPv4 address but is not a valid one")]
32    InvalidIpv4 { literal: String },
33    #[error(
34        "remote path is missing: the location must end in an absolute path like `/var/log/app.log`"
35    )]
36    AbsentPath,
37    #[error(
38        "SSH locations carry no query string or fragment; percent-encode those bytes in the path instead (`?` -> `%3F`, `#` -> `%23`)"
39    )]
40    QueryOrFragment,
41    #[error("percent escapes need two hexadecimal digits, e.g. `%20`")]
42    MalformedPercentEscape,
43    #[error("path cannot contain a NUL byte")]
44    NulInPath,
45    #[error("path contains a byte that must be percent-encoded (a space is `%20`)")]
46    UnencodedPathByte,
47    #[cfg(not(unix))]
48    #[error("the decoded path bytes are not representable as a native filename on this platform")]
49    UnrepresentablePath,
50    #[error("username/host may only contain ASCII letters, digits and `-._+`")]
51    InvalidAuthorityCharacter,
52    #[error(
53        "an endpoint carries no path: this value names files, so parse it as a location or file instead"
54    )]
55    PathOnEndpoint,
56    #[error(
57        "the path begins with `~` (a home query), which is not a canonical file; a session must expand it first"
58    )]
59    UnresolvedHome,
60    #[error("a canonical remote path is absolute: it must start with `/`")]
61    RelativePath,
62}