libsshpp v0.1.7
Modern C++17 wrapper for libssh
Loading...
Searching...
No Matches
error.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2#pragma once
3
4#include <sshpp/config.hpp>
5
6#include <sshpp/export.hpp>
7
8#include <string>
9#include <system_error>
10
11namespace sshpp {
12
15 const char* file = "";
16 int line = 0;
17 const char* function = "";
18};
19
20#define SSHPP_HERE ::sshpp::SourceLocation{__FILE__, __LINE__, __func__}
21
22enum class errc : int {
23 ok = 0,
24
25 // --- transport / session -------------------------------------------
26 fatal,
39
40 // --- host key ------------------------------------------------------
46
47 // --- authentication ---------------------------------------------------
56
57 // --- keys ---------------------------------------------------------------
62
63 // --- channels ---------------------------------------------------------------
69
70 // --- subsystems -----------------------------------------------------------------
75
76 // --- wrapper-level -------------------------------------------------------------------
81 unknown,
82};
83
84enum class sftp_errc : int {
85 ok = 0,
86 eof = 1,
87 no_such_file = 2,
89 failure = 4,
90 bad_message = 5,
91 no_connection = 6,
95 no_such_path = 10,
97 write_protect = 12,
98 no_media = 13,
100};
101
102SSHPP_API const std::error_category& ssh_category() noexcept;
103SSHPP_API const std::error_category& sftp_category() noexcept;
104
105SSHPP_API std::error_code make_error_code(errc e) noexcept;
106SSHPP_API std::error_code make_error_code(sftp_errc e) noexcept;
107
108} // namespace sshpp
109
110namespace std {
111template <> struct is_error_code_enum<sshpp::errc> : true_type {};
112template <> struct is_error_code_enum<sshpp::sftp_errc> : true_type {};
113} // namespace std
114
115namespace sshpp {
116
119struct SSHPP_API ErrorInfo {
120 std::error_code code{};
121 std::string message;
122 const char* operation = "";
124
125 [[nodiscard]] std::string to_string() const;
126 explicit operator bool() const noexcept { return static_cast<bool>(code); }
127};
128
129class SSHPP_API Error : public std::system_error {
130public:
131 explicit Error(ErrorInfo info);
132
133 const ErrorInfo& info() const noexcept { return info_; }
134 const char* operation() const noexcept { return info_.operation; }
135 const SourceLocation& where() const noexcept { return info_.where; }
136
137private:
138 ErrorInfo info_;
139};
140
141class SSHPP_API ConnectionError : public Error { using Error::Error; };
142class SSHPP_API TimeoutError : public ConnectionError { using ConnectionError::ConnectionError; };
143class SSHPP_API CancelledError : public ConnectionError { using ConnectionError::ConnectionError; };
144
145class SSHPP_API HostKeyError : public Error { using Error::Error; };
146class SSHPP_API AuthError : public Error { using Error::Error; };
147class SSHPP_API KeyError : public Error { using Error::Error; };
148class SSHPP_API ChannelError : public Error { using Error::Error; };
149class SSHPP_API SftpError : public Error { using Error::Error; };
150class SSHPP_API ScpError : public Error { using Error::Error; };
151class SSHPP_API ForwardingError : public ChannelError { using ChannelError::ChannelError; };
152class SSHPP_API ServerError : public Error { using Error::Error; };
153class SSHPP_API UsageError : public Error { using Error::Error; };
154
157[[noreturn]] SSHPP_API void throw_error(ErrorInfo info);
158
159} // namespace sshpp
160
161#if SSHPP_HEADER_ONLY
162#include <sshpp/detail/error.ipp>
163#endif
Definition error.hpp:146
Definition error.hpp:143
Definition error.hpp:148
Definition error.hpp:141
Definition error.hpp:129
const SourceLocation & where() const noexcept
Definition error.hpp:135
const ErrorInfo & info() const noexcept
Definition error.hpp:133
const char * operation() const noexcept
Definition error.hpp:134
Definition error.hpp:151
Definition error.hpp:145
Definition error.hpp:147
Definition error.hpp:150
Definition error.hpp:152
Definition error.hpp:149
Definition error.hpp:142
Definition error.hpp:153
Definition auth.hpp:18
SSHPP_INLINE const std::error_category & ssh_category() noexcept
Definition error.ipp:123
sftp_errc
Definition error.hpp:84
SSHPP_INLINE std::error_code make_error_code(errc e) noexcept
Definition error.ipp:133
SSHPP_INLINE void throw_error(ErrorInfo info)
Definition error.ipp:152
SSHPP_INLINE const std::error_category & sftp_category() noexcept
Definition error.ipp:128
errc
Definition error.hpp:22
@ passphrase_incorrect
@ host_key_type_mismatch
@ known_hosts_io_error
@ auth_method_unavailable
@ auth_no_more_methods
@ unsupported_key_type
@ banner_exchange_failed
@ unsupported_operation
@ key_generation_failed
@ channel_request_failed
Definition error.hpp:110
Definition error.hpp:119
std::string message
Definition error.hpp:121
Minimal std::source_location-like shim (this library targets C++17).
Definition error.hpp:14
const char * function
Definition error.hpp:17
const char * file
Definition error.hpp:15
int line
Definition error.hpp:16