Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
AsyncFibersErrorFormatter.h
1// Copyright (c) Stefano Cristiano
2// SPDX-License-Identifier: MIT
3#pragma once
4
5#include "../Common/ResultErrorFormatter.h"
6#include "AsyncFibersError.h"
7
8namespace SC
9{
12inline ResultErrorFormat formatAsyncFibersError(AsyncFibersError error, Span<char> output)
13{
14 ResultErrorFormatter formatter(output);
15 switch (error)
16 {
17 case AsyncFibersError::Cancelled: formatter.append("Fiber I/O operation was cancelled"); break;
18 case AsyncFibersError::SocketSendNoProgress: formatter.append("Socket send made no progress"); break;
19 case AsyncFibersError::InvalidFileHandle: formatter.append("File handle is invalid"); break;
20 case AsyncFibersError::UnexpectedEndOfFile:
21 formatter.append("File ended before the requested data was read");
22 break;
23 case AsyncFibersError::WrongOwnerThread: formatter.append("Fiber I/O must run on its owner thread"); break;
24 case AsyncFibersError::FiberContextRequired: formatter.append("Operation requires a running fiber"); break;
25 case AsyncFibersError::CommandStorageEmpty: formatter.append("Command queue has no storage"); break;
26 case AsyncFibersError::InvalidCommand: formatter.append("Command is invalid"); break;
27 case AsyncFibersError::CommandQueueFull: formatter.append("Command queue is full"); break;
28 default: return ResultErrorFormatter::failure(ResultErrorFormatStatus::UnknownError, output);
29 }
30 return formatter.finish();
31}
32
33inline ResultErrorFormat formatAsyncFibersError(Result result, Span<char> output)
34{
35 if (result)
36 return ResultErrorFormatter::failure(ResultErrorFormatStatus::NotAnError, output);
37 if (result.category() != AsyncFibersResultCategory)
38 return ResultErrorFormatter::failure(ResultErrorFormatStatus::ForeignCategory, output);
39 return formatAsyncFibersError(static_cast<AsyncFibersError>(result.errorValue()), output);
40}
41} // namespace SC
AsyncFibersError
Stable portable failures owned by the AsyncFibers bridge.
Definition AsyncFibersError.h:15