Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
ProcessError.h
1// Copyright (c) Stefano Cristiano
2// SPDX-License-Identifier: MIT
3#pragma once
4
5#include "../Common/Result.h"
6
7namespace SC
8{
11
13enum class ProcessError : uint32_t
14{
15 ProcessChainEmpty = 1,
16 ProcessAlreadyInChain,
17 InvalidInputRedirection,
18 InvalidOutputRedirection,
19 UnsupportedInputRedirection,
20 UnsupportedOutputRedirection,
21 ArgumentCapacityExceeded,
22 EnvironmentCapacityExceeded,
23 WaitFailed,
24 LaunchFailed,
25 CloneFailed,
26 PathCapacityExceeded,
27 PathMustBeAbsolute,
28 InvalidPath,
29 PathResolutionFailed,
30};
31
34enum class ProcessErrorDetail : uint32_t
35{
36 None = 0,
37 PosixWaitPid,
38 WindowsGetExitCodeProcess,
39 PosixFork,
40 PosixExec,
41 PosixBuildResolveExecutablePath,
42 PosixDuplicateDescriptor,
43 PosixResetSignalHandlers,
44 PosixChangeWorkingDirectory,
45 WindowsSetHandleInformation,
46 WindowsCreateProcess,
47 WindowsRtlCloneUserProcess,
48 WindowsNtWaitForSingleObject,
49 WindowsResolveWorkingDirectory,
50 WindowsPrepareExecutableTransportPath,
51 WindowsPrepareWorkingDirectoryTransportPath,
52 WindowsNormalizeExecutablePath,
53};
54
56static constexpr ResultCategory ProcessResultCategory = ResultCategory(5);
57
61struct [[nodiscard]] ResultProcess
62{
63 Result result;
64 ProcessErrorDetail detail = ProcessErrorDetail::None;
65 uint32_t nativeError = 0;
66
67 explicit constexpr ResultProcess(bool valid = true) : result(valid) {}
68 constexpr ResultProcess(ProcessError error, ProcessErrorDetail detail = ProcessErrorDetail::None,
69 uint32_t nativeError = 0)
70 : result(Result::Error(ProcessResultCategory, error)), detail(detail), nativeError(nativeError)
71 {}
72 constexpr ResultProcess(Result result) : result(result) {}
73
74 template <typename ResultLike>
75 constexpr ResultProcess(const ResultLike& other) : result(other.toResult())
76 {}
77
78 explicit constexpr operator bool() const { return static_cast<bool>(result); }
79
80 constexpr operator Result() const { return result; }
81
82 constexpr Result toResult() const { return result; }
83 constexpr bool isError(ProcessError error) const { return result.isError(ProcessResultCategory, error); }
84};
85
87} // namespace SC
ProcessErrorDetail
Stable diagnostic stages for Process failures.
Definition ProcessError.h:35
ProcessError
Stable error codes returned by the Process library.
Definition ProcessError.h:14
Process result retaining optional backend and native platform details.
Definition ProcessError.h:62