Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
AsyncErrorFormatter.h
1// Copyright (c) Stefano Cristiano
2// SPDX-License-Identifier: MIT
3#pragma once
4
5#include "../Common/ResultErrorFormatter.h"
6#include "AsyncError.h"
7
8namespace SC
9{
12inline ResultErrorFormat formatAsyncError(AsyncError error, Span<char> output)
13{
14 ResultErrorFormatter formatter(output);
15 switch (error)
16 {
17 case AsyncError::AlreadyInitialized: formatter.append("Event loop is already initialized"); break;
18 case AsyncError::NotInitialized: formatter.append("Event loop is not initialized"); break;
19 case AsyncError::RequestInUse: formatter.append("Request is already in use"); break;
20 case AsyncError::RequestNotActive: formatter.append("Request is not active"); break;
21 case AsyncError::SequencedTimeout: formatter.append("Sequenced timeout cannot be unscheduled"); break;
22 case AsyncError::TimeoutTransitionInProgress: formatter.append("Timeout is changing state"); break;
23 case AsyncError::InvalidState: formatter.append("Operation is invalid in the current state"); break;
24 case AsyncError::InvalidCallback: formatter.append("Work callback is invalid"); break;
25 case AsyncError::MissingThreadPool: formatter.append("Thread pool has not been set"); break;
26 case AsyncError::InvalidHandle: formatter.append("Handle is invalid"); break;
27 case AsyncError::InvalidSignal: formatter.append("Signal number is invalid"); break;
28 case AsyncError::UnsupportedSignal: formatter.append("Signal cannot be watched"); break;
29 case AsyncError::OperationUnsupported: formatter.append("Operation is unsupported"); break;
30 case AsyncError::SubmissionAlreadyPending: formatter.append("Submission is already pending"); break;
31 case AsyncError::NoPendingSubmission: formatter.append("No submission is pending"); break;
32 case AsyncError::ManualCompletionRequired: formatter.append("Manual completion mode is required"); break;
33 case AsyncError::CompletionAlreadyPosted: formatter.append("Completion has already been posted"); break;
34 case AsyncError::InvalidSocketHandle: formatter.append("Socket handle is invalid"); break;
35 case AsyncError::InvalidAddress: formatter.append("Socket address is invalid"); break;
36 case AsyncError::EmptyBuffer: formatter.append("Buffer is empty"); break;
37 case AsyncError::MissingAcceptData: formatter.append("Accept request data is missing"); break;
38 case AsyncError::InvalidFileHandle: formatter.append("File handle is invalid"); break;
39 case AsyncError::EmptyTransfer: formatter.append("Transfer length is zero"); break;
40 case AsyncError::OperationNotSet: formatter.append("File-system operation has not been set"); break;
41 case AsyncError::InvalidPath: formatter.append("Path is invalid"); break;
42 case AsyncError::InvalidSourcePath: formatter.append("Source path is invalid"); break;
43 case AsyncError::InvalidDestinationPath: formatter.append("Destination path is invalid"); break;
44 case AsyncError::EventLoopCreationFailed: formatter.append("Event loop could not be created"); break;
45 case AsyncError::WakeUpInitializationFailed: formatter.append("Event-loop wake-up could not be initialized"); break;
46 case AsyncError::WakeUpFailed: formatter.append("Event loop could not be woken"); break;
47 case AsyncError::InvalidEventLoopHandle: formatter.append("Event-loop handle is invalid"); break;
48 case AsyncError::InvalidWakeUpHandle: formatter.append("Event-loop wake-up handle is invalid"); break;
49 case AsyncError::WatcherRegistrationFailed: formatter.append("Event watcher could not be registered"); break;
50 case AsyncError::WatcherRemovalFailed: formatter.append("Event watcher could not be removed"); break;
51 case AsyncError::EventLoopFlushFailed: formatter.append("Event-loop changes could not be submitted"); break;
52 case AsyncError::EventLoopPollFailed: formatter.append("Event loop could not poll for events"); break;
53 case AsyncError::EventCompletionFailed: formatter.append("Event could not be completed"); break;
54 case AsyncError::SubmissionCapacityExhausted:
55 formatter.append("Event-loop submission capacity is exhausted");
56 break;
57 case AsyncError::SubmissionFailed: formatter.append("Event-loop submission failed"); break;
58 case AsyncError::ProcessWatcherCreationFailed: formatter.append("Process watcher could not be created"); break;
59 case AsyncError::ProcessWatcherRemovalFailed: formatter.append("Process watcher could not be removed"); break;
60 case AsyncError::ProcessWaitFailed: formatter.append("Process exit could not be observed"); break;
61 case AsyncError::SignalWatcherCreationFailed: formatter.append("Signal watcher could not be created"); break;
62 case AsyncError::SignalWatcherRemovalFailed: formatter.append("Signal watcher could not be removed"); break;
63 case AsyncError::SignalReadFailed: formatter.append("Signal event could not be read"); break;
64 case AsyncError::SignalSubscriberLimitReached: formatter.append("Signal subscriber limit was reached"); break;
65 case AsyncError::InvalidEventIndex: formatter.append("Event index is invalid"); break;
66 case AsyncError::CancellationFailed: formatter.append("Operation could not be cancelled"); break;
67 case AsyncError::SocketConnectFailed: formatter.append("Socket could not connect"); break;
68 case AsyncError::SocketSendFailed: formatter.append("Socket data could not be sent"); break;
69 case AsyncError::SocketReceiveFailed: formatter.append("Socket data could not be received"); break;
70 case AsyncError::SocketSendIncomplete: formatter.append("Socket data was only partially sent"); break;
71 case AsyncError::FileWriteFailed: formatter.append("File data could not be written"); break;
72 case AsyncError::FileWriteIncomplete: formatter.append("File data was only partially written"); break;
73 case AsyncError::DescriptorAssociationFailed:
74 formatter.append("Descriptor could not be associated with event loop");
75 break;
76 case AsyncError::SocketCompletionFailed: formatter.append("Socket operation could not be completed"); break;
77 case AsyncError::SocketCreationFailed: formatter.append("Socket could not be created"); break;
78 case AsyncError::SocketAcceptFailed: formatter.append("Socket connection could not be accepted"); break;
79 case AsyncError::SocketAcceptFinalizationFailed: formatter.append("Accepted socket could not be finalized"); break;
80 case AsyncError::SocketExtensionUnavailable: formatter.append("Required socket operation is unavailable"); break;
81 case AsyncError::SocketBindFailed: formatter.append("Socket could not be bound"); break;
82 case AsyncError::SocketBufferCountExceeded: formatter.append("Too many buffers for one socket send"); break;
83 case AsyncError::FileReadFailed: formatter.append("File data could not be read"); break;
84 case AsyncError::FileSeekFailed: formatter.append("File position could not be set"); break;
85 case AsyncError::FileSendFailed: formatter.append("File data could not be sent"); break;
86 case AsyncError::FileSendCompletionFailed: formatter.append("File send could not be completed"); break;
87 case AsyncError::FileSendIncomplete: formatter.append("File data was only partially sent"); break;
88 case AsyncError::InvalidTransferPipe: formatter.append("File transfer pipe is invalid"); break;
89 case AsyncError::ThreadPoolAlreadyStopped: formatter.append("Thread pool stopped before requests completed"); break;
90 case AsyncError::ActiveRequestsRemain: formatter.append("Event loop still has active requests after close"); break;
91 case AsyncError::InvalidSubmissionState:
92 formatter.append("Request cannot be submitted in its current state");
93 break;
94 default: return ResultErrorFormatter::failure(ResultErrorFormatStatus::UnknownError, output);
95 }
96 return formatter.finish();
97}
98
99inline ResultErrorFormat formatAsyncError(Result result, Span<char> output)
100{
101 if (result)
102 return ResultErrorFormatter::failure(ResultErrorFormatStatus::NotAnError, output);
103 if (result.category() != AsyncResultCategory)
104 return ResultErrorFormatter::failure(ResultErrorFormatStatus::ForeignCategory, output);
105 return formatAsyncError(static_cast<AsyncError>(result.errorValue()), output);
106}
107} // namespace SC
AsyncError
Stable portable failures owned by Async.
Definition AsyncError.h:15