40 lines
2.4 KiB
Markdown
40 lines
2.4 KiB
Markdown
# Functional Compact Status, Bounded Contexts, and Error Adapters
|
|
Task ID: M-FUNCTIONAL-02
|
|
Phase: P1
|
|
Status: APPROVED
|
|
Contracts: C-01, C-02, C-05 (G-ERROR)
|
|
|
|
## 1. Context and baseline
|
|
`include/Void/Functional/Error.hpp` stores free-form message strings and unbounded `shared_ptr<const Error>` chains with recursive destruction and no machine-readable classification.
|
|
|
|
## 2. Deliverables
|
|
- `ErrorKind`, `ErrorCode`, `Status`, reserved domain constants, bounded message/frame/format limits, and iterative `~Error()` in `include/Void/Functional/Error.hpp`.
|
|
- `fail(Status)` and `fail(ErrorKind, ...)` factories in `include/Void/Functional/Result.hpp`.
|
|
- `include/Void/Functional/Adapters.hpp` (`adapt`, `try_invoke`, `from_errno`).
|
|
- `tests/standalone/Functional/ErrorStatus.cpp`.
|
|
|
|
## 3. Exact files and interfaces
|
|
- `include/Void/Functional/Error.hpp`:
|
|
- `ErrorKind`: `invalid_argument`, `not_found`, `conflict`, `cancelled`, `timeout`, `overloaded`, `unsupported`, `io`, `corrupt`, `exhausted`, `internal`.
|
|
- `Status { ErrorKind kind; ErrorCode code; }` and `explicit Error(Status) noexcept` (zero heap allocation).
|
|
- Limits: `kDefaultMaxErrorFrames = 16`, `kDefaultMaxErrorMessageBytes = 1024`, `kDefaultMaxFormattedErrorBytes = 16 * 1024`.
|
|
- `with_context()` preserves root `Status` and `std::error_code`, pins the root cause at the tail when capping > 16 frames, and sets `truncated() == true`.
|
|
- `include/Void/Functional/Result.hpp`: typed `fail(...)` overloads.
|
|
- `include/Void/Functional/Adapters.hpp`: `adapt`, `try_invoke`, `from_errno`.
|
|
|
|
## 4. Edge cases
|
|
- `Error(Status)` makes zero heap allocations.
|
|
- `try_invoke` must ALWAYS rethrow `std::bad_alloc` and any exception where `map_exception` returns `std::nullopt`.
|
|
- `adapt` handles `void`, move-only values, and never invokes `map_error` on success.
|
|
- 20-layer context chains preserve `ErrorKind`, `ErrorCode`, `system_code`, and root cause message.
|
|
|
|
## 5. Acceptance criteria
|
|
- Existing 1.x `Result*` tests pass unchanged; `ErrorStatus` suite passes under `-Werror` and ASan/UBSan.
|
|
|
|
## 6. Verification commands
|
|
```sh
|
|
dev cpp-gcc -c cmake -S . -B /tmp/void-p1-functional -G Ninja -DCMAKE_CXX_COMPILER=g++ -DCMAKE_BUILD_TYPE=Debug -DVOID_ENABLED_MODULES="Functional;Testing" -DVOID_WARNINGS_AS_ERRORS=ON
|
|
dev cpp-gcc -c cmake --build /tmp/void-p1-functional --parallel 4
|
|
dev cpp-gcc -c /tmp/void-p1-functional/tests/VoidTests --filter "ErrorStatus*|Result*"
|
|
```
|