Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
process_error.h
1#ifndef SOURCEMETA_CORE_PROCESS_ERROR_H_
2#define SOURCEMETA_CORE_PROCESS_ERROR_H_
3
4#ifndef SOURCEMETA_CORE_PROCESS_EXPORT
5#include <sourcemeta/core/process_export.h>
6#endif
7
8#include <sourcemeta/core/error.h>
9
10#include <initializer_list> // std::initializer_list
11#include <span> // std::span
12#include <string> // std::string
13#include <string_view> // std::string_view
14#include <vector> // std::vector
15
16namespace sourcemeta::core {
17
18SOURCEMETA_CORE_ERROR_WARNINGS_PUSH
19
22class SOURCEMETA_CORE_PROCESS_EXPORT ProcessProgramNotFoundError
23 : public Error {
24public:
26 ProcessProgramNotFoundError(const std::string_view program)
27 : Error{"Could not locate the requested program"}, program_{program} {}
28
30 [[nodiscard]] auto program() const noexcept -> std::string_view {
31 return this->program_;
32 }
33
34private:
35 std::string program_;
36};
37
40class SOURCEMETA_CORE_PROCESS_EXPORT ProcessSpawnError : public Error {
41public:
43 ProcessSpawnError(const std::string_view program,
44 std::initializer_list<std::string_view> arguments)
45 : Error{"Process terminated abnormally"}, program_{program},
46 arguments_{arguments.begin(), arguments.end()} {}
47
49 ProcessSpawnError(const std::string_view program,
50 std::span<const std::string_view> arguments)
51 : Error{"Process terminated abnormally"}, program_{program},
52 arguments_{arguments.begin(), arguments.end()} {}
53
55 [[nodiscard]] auto program() const noexcept -> std::string_view {
56 return this->program_;
57 }
58
60 [[nodiscard]] auto arguments() const noexcept
61 -> const std::vector<std::string> & {
62 return this->arguments_;
63 }
64
65private:
66 std::string program_;
67 std::vector<std::string> arguments_;
68};
69
70SOURCEMETA_CORE_ERROR_WARNINGS_POP
71
72} // namespace sourcemeta::core
73
74#endif
Error(const StaticString message) noexcept
Construct the error given its message.
Definition error_base.h:84
ProcessSpawnError(const std::string_view program, std::span< const std::string_view > arguments)
Construct the error given the offending program and its arguments.
Definition process_error.h:49
auto arguments() const noexcept -> const std::vector< std::string > &
The arguments the program was spawned with.
Definition process_error.h:60
auto program() const noexcept -> std::string_view
The offending program.
Definition process_error.h:30
ProcessProgramNotFoundError(const std::string_view program)
Construct the error given the offending program.
Definition process_error.h:26
ProcessSpawnError(const std::string_view program, std::initializer_list< std::string_view > arguments)
Construct the error given the offending program and its arguments.
Definition process_error.h:43
auto program() const noexcept -> std::string_view
The offending program.
Definition process_error.h:55