Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
io_error.h
1#ifndef SOURCEMETA_CORE_IO_ERROR_H_
2#define SOURCEMETA_CORE_IO_ERROR_H_
3
4#ifndef SOURCEMETA_CORE_IO_EXPORT
5#include <sourcemeta/core/io_export.h>
6#endif
7
8#include <sourcemeta/core/error.h>
9
10#include <filesystem> // std::filesystem::path
11#include <system_error> // std::error_code
12#include <utility> // std::move
13
14namespace sourcemeta::core {
15
16SOURCEMETA_CORE_ERROR_WARNINGS_PUSH
17
20class SOURCEMETA_CORE_IO_EXPORT FileViewError : public Error {
21public:
23 FileViewError(const StaticString message, std::filesystem::path path)
24 : Error{message}, path_{std::move(path)} {}
25
27 [[nodiscard]] auto path() const noexcept -> const std::filesystem::path & {
28 return this->path_;
29 }
30
31private:
32 std::filesystem::path path_;
33};
34
37class SOURCEMETA_CORE_IO_EXPORT IOFileNotFoundError : public Error {
38public:
40 IOFileNotFoundError(std::filesystem::path path)
41 : Error{"File not found"}, path_{std::move(path)} {}
42
44 [[nodiscard]] auto path() const noexcept -> const std::filesystem::path & {
45 return this->path_;
46 }
47
48private:
49 std::filesystem::path path_;
50};
51
54class SOURCEMETA_CORE_IO_EXPORT IOFilePermissionError : public Error {
55public:
57 IOFilePermissionError(std::filesystem::path path)
58 : Error{"Permission denied"}, path_{std::move(path)} {}
59
61 [[nodiscard]] auto path() const noexcept -> const std::filesystem::path & {
62 return this->path_;
63 }
64
65private:
66 std::filesystem::path path_;
67};
68
71class SOURCEMETA_CORE_IO_EXPORT IOIsADirectoryError : public Error {
72public:
74 IOIsADirectoryError(std::filesystem::path path)
75 : Error{"Expected a file but got a directory"}, path_{std::move(path)} {}
76
78 [[nodiscard]] auto path() const noexcept -> const std::filesystem::path & {
79 return this->path_;
80 }
81
82private:
83 std::filesystem::path path_;
84};
85
88class SOURCEMETA_CORE_IO_EXPORT IONotADirectoryError : public Error {
89public:
91 IONotADirectoryError(std::filesystem::path path)
92 : Error{"Expected a directory but got a file"}, path_{std::move(path)} {}
93
95 [[nodiscard]] auto path() const noexcept -> const std::filesystem::path & {
96 return this->path_;
97 }
98
99private:
100 std::filesystem::path path_;
101};
102
105class SOURCEMETA_CORE_IO_EXPORT IOFileAlreadyExistsError : public Error {
106public:
108 IOFileAlreadyExistsError(std::filesystem::path path)
109 : Error{"File already exists"}, path_{std::move(path)} {}
110
112 [[nodiscard]] auto path() const noexcept -> const std::filesystem::path & {
113 return this->path_;
114 }
115
116private:
117 std::filesystem::path path_;
118};
119
122class SOURCEMETA_CORE_IO_EXPORT IOFilesystemError : public Error {
123public:
126 IOFilesystemError(const StaticString message, std::filesystem::path path,
127 const std::error_code code)
128 : Error{message}, path_{std::move(path)}, code_{code} {}
129
132 IOFilesystemError(const StaticString message, std::filesystem::path path,
133 std::filesystem::path other, const std::error_code code)
134 : Error{message}, path_{std::move(path)}, other_{std::move(other)},
135 code_{code} {}
136
138 [[nodiscard]] auto path() const noexcept -> const std::filesystem::path & {
139 return this->path_;
140 }
141
143 [[nodiscard]] auto other() const noexcept -> const std::filesystem::path & {
144 return this->other_;
145 }
146
148 [[nodiscard]] auto code() const noexcept -> std::error_code {
149 return this->code_;
150 }
151
152private:
153 std::filesystem::path path_;
154 std::filesystem::path other_;
155 std::error_code code_;
156};
157
161class SOURCEMETA_CORE_IO_EXPORT IOReadOutOfBoundsError : public Error {
162public:
163 IOReadOutOfBoundsError() noexcept
164 : Error{"Read past the end of the underlying data"} {}
165};
166
169class SOURCEMETA_CORE_IO_EXPORT IOStreamWriteError : public Error {
170public:
171 IOStreamWriteError() noexcept : Error{"Failed to write to stream"} {}
172};
173
174SOURCEMETA_CORE_ERROR_WARNINGS_POP
175
176} // namespace sourcemeta::core
177
178#endif
auto message() const noexcept -> StaticString
Definition error_base.h:78
Error(const StaticString message) noexcept
Construct the error given its message.
Definition error_base.h:84
auto path() const noexcept -> const std::filesystem::path &
The offending path.
Definition io_error.h:138
IOFileNotFoundError(std::filesystem::path path)
Construct the error given the offending path.
Definition io_error.h:40
IOFilePermissionError(std::filesystem::path path)
Construct the error given the offending path.
Definition io_error.h:57
auto path() const noexcept -> const std::filesystem::path &
The offending path.
Definition io_error.h:27
IOIsADirectoryError(std::filesystem::path path)
Construct the error given the offending path.
Definition io_error.h:74
auto code() const noexcept -> std::error_code
The code the platform reported.
Definition io_error.h:148
IOFilesystemError(const StaticString message, std::filesystem::path path, std::filesystem::path other, const std::error_code code)
Definition io_error.h:132
auto path() const noexcept -> const std::filesystem::path &
The offending path.
Definition io_error.h:44
IOFileAlreadyExistsError(std::filesystem::path path)
Construct the error given the offending path.
Definition io_error.h:108
auto path() const noexcept -> const std::filesystem::path &
The offending path.
Definition io_error.h:78
auto path() const noexcept -> const std::filesystem::path &
The offending path.
Definition io_error.h:112
FileViewError(const StaticString message, std::filesystem::path path)
Construct the error given a message and the offending path.
Definition io_error.h:23
auto path() const noexcept -> const std::filesystem::path &
The offending path.
Definition io_error.h:95
IOFilesystemError(const StaticString message, std::filesystem::path path, const std::error_code code)
Definition io_error.h:126
auto other() const noexcept -> const std::filesystem::path &
The other path the operation names, empty when it names only one.
Definition io_error.h:143
auto path() const noexcept -> const std::filesystem::path &
The offending path.
Definition io_error.h:61
IONotADirectoryError(std::filesystem::path path)
Construct the error given the offending path.
Definition io_error.h:91
Definition text_static_string.h:20