FastLED 3.10.8
Loading...
Searching...
No Matches
error_code.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/task/promise.h"
4#include "fl/stl/stdint.h"
5#include "fl/stl/string.h"
6#include "fl/stl/noexcept.h"
7
8namespace fl {
9namespace asio {
10
25
31struct error_code {
33 fl::string message; // optional human-readable detail
34
37 error_code(errc c, const fl::string &msg) FL_NO_EXCEPT : code(c), message(msg) {}
38 error_code(errc c, const char *msg) FL_NO_EXCEPT : code(c), message(msg) {}
39
41 explicit operator bool() const FL_NO_EXCEPT { return code != errc::success; }
42
44 bool ok() const FL_NO_EXCEPT { return code == errc::success; }
45
48 if (e.is_empty()) {
49 return error_code();
50 }
51 return error_code(errc::unknown, e.message);
52 }
53
56 if (ok()) {
57 return fl::task::Error();
58 }
60 }
61
63 static error_code from_errno(int platform_errno) FL_NO_EXCEPT;
64
65 bool operator==(const error_code &o) const FL_NO_EXCEPT { return code == o.code; }
66 bool operator!=(const error_code &o) const FL_NO_EXCEPT { return code != o.code; }
67};
68
69} // namespace asio
70} // namespace fl
errc
Asio-compatible error code enumeration.
Definition error_code.h:13
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
Base definition for an LED controller.
Definition crgb.hpp:179
Promise-based fluent API for FastLED - standalone async primitives.
static error_code from_error(const fl::task::Error &e) FL_NO_EXCEPT
Convert from fl::task::Error for interop with existing FastLED code.
Definition error_code.h:47
bool ok() const FL_NO_EXCEPT
Convenience: true if no error.
Definition error_code.h:44
bool operator!=(const error_code &o) const FL_NO_EXCEPT
Definition error_code.h:66
error_code(errc c, const char *msg) FL_NO_EXCEPT
Definition error_code.h:38
static error_code from_errno(int platform_errno) FL_NO_EXCEPT
Convert from platform errno value.
error_code(errc c) FL_NO_EXCEPT
Definition error_code.h:36
error_code(errc c, const fl::string &msg) FL_NO_EXCEPT
Definition error_code.h:37
fl::task::Error to_error() const FL_NO_EXCEPT
Convert to fl::task::Error for interop with existing FastLED code.
Definition error_code.h:55
bool operator==(const error_code &o) const FL_NO_EXCEPT
Definition error_code.h:65
error_code() FL_NO_EXCEPT
Definition error_code.h:35
Asio-compatible error code: numeric code + optional human-readable message.
Definition error_code.h:31
Error type for promises.
Definition promise.h:39