1#ifndef SOURCEMETA_CORE_IO_ERROR_H_
2#define SOURCEMETA_CORE_IO_ERROR_H_
4#ifndef SOURCEMETA_CORE_IO_EXPORT
5#include <sourcemeta/core/io_export.h>
8#include <sourcemeta/core/error.h>
11#include <system_error>
14namespace sourcemeta::core {
16SOURCEMETA_CORE_ERROR_WARNINGS_PUSH
27 [[nodiscard]]
auto path() const noexcept -> const std::filesystem::
path & {
32 std::filesystem::path path_;
41 :
Error{
"File not found"}, path_{std::move(
path)} {}
44 [[nodiscard]]
auto path() const noexcept -> const std::filesystem::
path & {
49 std::filesystem::path path_;
58 :
Error{
"Permission denied"}, path_{std::move(
path)} {}
61 [[nodiscard]]
auto path() const noexcept -> const std::filesystem::
path & {
66 std::filesystem::path path_;
75 :
Error{
"Expected a file but got a directory"}, path_{std::move(
path)} {}
78 [[nodiscard]]
auto path() const noexcept -> const std::filesystem::
path & {
83 std::filesystem::path path_;
92 :
Error{
"Expected a directory but got a file"}, path_{std::move(
path)} {}
95 [[nodiscard]]
auto path() const noexcept -> const std::filesystem::
path & {
100 std::filesystem::path path_;
109 :
Error{
"File already exists"}, path_{std::move(
path)} {}
112 [[nodiscard]]
auto path() const noexcept -> const std::filesystem::
path & {
117 std::filesystem::path path_;
127 const std::error_code
code)
133 std::filesystem::path
other,
const std::error_code
code)
138 [[nodiscard]]
auto path() const noexcept -> const std::filesystem::
path & {
143 [[nodiscard]]
auto other() const noexcept -> const std::filesystem::
path & {
148 [[nodiscard]]
auto code() const noexcept -> std::error_code {
153 std::filesystem::path path_;
154 std::filesystem::path other_;
155 std::error_code code_;
161class SOURCEMETA_CORE_IO_EXPORT IOReadOutOfBoundsError :
public Error {
163 IOReadOutOfBoundsError() noexcept
164 :
Error{
"Read past the end of the underlying data"} {}
169class SOURCEMETA_CORE_IO_EXPORT IOStreamWriteError :
public Error {
171 IOStreamWriteError() noexcept :
Error{
"Failed to write to stream"} {}
174SOURCEMETA_CORE_ERROR_WARNINGS_POP
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