Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
managed_diagnostics.hpp
1// Copyright (c) 2026 ttldtor.
2// SPDX-License-Identifier: BSL-1.0
3#pragma once
4
5#include <portals/application.hpp>
6#include <portals/detail/pss_data.hpp>
7#include <portals/log_file_error.hpp>
8#include <portals/numeric.hpp>
9#include <portals/password.hpp>
10#include <portals/pss_file_error.hpp>
11#include <portals/scene_resource_error.hpp>
12#include <portals/shortcut.hpp>
13#include <portals/style.hpp>
14#include <portals/text_resource.hpp>
15
16#include <cstddef>
17#include <functional>
18#include <memory>
19#include <optional>
20#include <source_location>
21#include <string>
22#include <variant>
23#include <vector>
24
25namespace portals {
27
28class ManagedScene;
29enum class AsyncError;
30enum class SearchError;
31enum class SourceError;
32
33namespace detail {
37class ManagedErrorReceipt {
38public:
39 ManagedErrorReceipt() = default;
40
41private:
42 friend class portals::ManagedScene;
43 std::weak_ptr<const void> collector_;
44};
45} // namespace detail
46
60
66 std::variant<TreeError, StyleError, ApplicationError> cause;
67 std::optional<ApplicationError> application;
68 std::optional<TreeError> cleanup;
69 std::optional<TextError> text{};
70 std::optional<TextResourceError> resource{};
71 std::optional<PssError>
72 pss{};
73 std::optional<PssFileError> file{};
78 std::shared_ptr<const std::string> styleSource{};
79 std::optional<ShortcutError> shortcut{};
80 std::optional<std::source_location>
82 const char *operation{};
83 std::optional<std::source_location>
85 const char *execution{};
86 bool setupStopped{};
90 std::shared_ptr<const SceneResourceError> sceneResource{};
92 std::optional<PasswordFailure> password{};
93 std::optional<AsyncError> async{};
94 std::optional<BackgroundError> background{};
95 std::optional<SearchError> search{};
96 std::optional<NumericError> numeric{};
97 std::optional<SourceError> source{};
99 std::shared_ptr<const DocumentOperationFailure> document{};
100 std::optional<FileLogFailure> logFile{};
101};
102
103namespace detail {
110ManagedError passwordError(ManagedPhase phase, NodeId node, PasswordFailure failure);
111} // namespace detail
112
115 std::size_t maxErrors{64};
116 std::size_t maxContexts{8};
117 std::size_t maxContextBytes{1024};
118};
119
122 std::string operation = std::string(0, '\0');
123 std::string name = std::string(0, '\0');
124 std::string scope = std::string(0, '\0');
125 std::string expectedType = std::string(0, '\0');
126 std::source_location origin{};
127};
128
133 std::vector<ManagedDiagnosticContext> contexts = std::vector<ManagedDiagnosticContext>(0);
134 std::source_location origin{};
140};
141
145 std::vector<ManagedDiagnostic> errors = std::vector<ManagedDiagnostic>(0);
146 std::size_t droppedErrors{};
147 std::size_t contextFailures{};
148 std::size_t observerFailures{};
150 bool closed{};
151};
152
154using ManagedErrorHandler = std::function<void(const ManagedDiagnostic &)>;
155
156} // namespace portals
Additive lifecycle owner over one existing Application subtree. UI affine and nonmovable....
Definition managed.hpp:530
Default-empty internal evidence that a short error entered one live collector. Copies preserve proven...
Definition managed_diagnostics.hpp:37
Public Portals API.
Definition action.hpp:8
SearchError
Search/provider errors, separate from scheduler and UI delivery errors.
Definition search.hpp:12
@ TEXT
Text category without content.
Definition diagnostics.hpp:64
std::variant< TreeError, TextError, PasswordInputError, SecureStringFailure, PasswordValueAccessFailure< SecureStringFailure >, PasswordValueAccessFailure< TextError >, PasswordValueAccessFailure< std::monostate > > PasswordFailure
Owning original causes, including independently retained callback/cleanup diagnostics.
Definition password.hpp:42
AsyncError
Failures of the optional single-frame UI coroutine adapter.
Definition async.hpp:25
ManagedPhase
Boundary at which a managed operation failed.
Definition managed_diagnostics.hpp:48
@ STYLE
Register or apply styles, including a theme change.
Definition managed_diagnostics.hpp:52
@ LAYOUT
Read final arranged geometry or deliver a deferred owning layout observation.
Definition managed_diagnostics.hpp:58
@ STATE
Create and retain a scene-owned property.
Definition managed_diagnostics.hpp:50
@ CLEANUP
Remove a managed subtree or retire the scene and its registrations.
Definition managed_diagnostics.hpp:56
@ MOUNT
Create the scene root or attach and register a managed widget.
Definition managed_diagnostics.hpp:49
@ BIND
Register a managed callback, binding or presentation adapter.
Definition managed_diagnostics.hpp:51
@ RUN
Enter the application runner or propagate a failure from it.
Definition managed_diagnostics.hpp:55
SourceError
Source protocol and admission failures, independent of a provider's storage format.
Definition source_budget.hpp:14
std::function< void(const ManagedDiagnostic &)> ManagedErrorHandler
Scene-owned UI observer; the diagnostic is borrowed only until the call returns.
Definition managed_diagnostics.hpp:154
@ INPUT
Read, decode and enqueue terminal input or resize events.
Definition application.hpp:18
@ PREPARE
Synchronize scene state and, when enabled, prepare views after preliminary layout.
Definition application.hpp:20
Source/admission cause and, when applicable, the precise decoder failure.
Definition document_search.hpp:30
Owning snapshot or drained history; counters saturate at size_t's maximum.
Definition managed_diagnostics.hpp:143
std::size_t droppedErrors
Reports omitted because the bounded history was full.
Definition managed_diagnostics.hpp:146
std::vector< ManagedDiagnostic > errors
Retained errors in report order; no borrowed widget state.
Definition managed_diagnostics.hpp:145
std::size_t contextFailures
Reports whose breadcrumb allocation failed.
Definition managed_diagnostics.hpp:147
std::size_t suppressedNotifications
Nested reports which could not invoke onError recursively.
Definition managed_diagnostics.hpp:149
std::size_t observerFailures
Observer exceptions, separate from original causes.
Definition managed_diagnostics.hpp:148
bool closed
Scene was closed when this snapshot was taken.
Definition managed_diagnostics.hpp:150
Owning causal breadcrumb; source_location refers to compiler-owned static source names.
Definition managed_diagnostics.hpp:121
std::string scope
Optional application scope name.
Definition managed_diagnostics.hpp:124
std::string expectedType
Optional expected widget or value type name.
Definition managed_diagnostics.hpp:125
std::source_location origin
Original registration/lookup call site, captured before deferral.
Definition managed_diagnostics.hpp:126
std::string operation
Operation label, copied without formatting or interpretation.
Definition managed_diagnostics.hpp:122
std::string name
Optional application reference or property name.
Definition managed_diagnostics.hpp:123
Finite error-history and causal-context budgets. All limits must be positive.
Definition managed_diagnostics.hpp:114
std::size_t maxContextBytes
Total bytes retained across breadcrumb labels in each error.
Definition managed_diagnostics.hpp:117
std::size_t maxContexts
Maximum causal breadcrumbs in each error, in supplied order.
Definition managed_diagnostics.hpp:116
std::size_t maxErrors
Maximum retained errors; the oldest entries survive overflow.
Definition managed_diagnostics.hpp:115
One owned error and its bounded causal trace, independent of widget lifetime.
Definition managed_diagnostics.hpp:130
bool notificationSuppressed
A nested report was stored without recursive notification.
Definition managed_diagnostics.hpp:138
ManagedError error
Definition managed_diagnostics.hpp:131
bool storageOverflow
Observer-only fallback: history was already full.
Definition managed_diagnostics.hpp:137
std::vector< ManagedDiagnosticContext > contexts
Owning breadcrumbs, oldest supplied context first; empty construction can propagate allocation failur...
Definition managed_diagnostics.hpp:133
std::source_location origin
Report call site; not a physical runtime stack.
Definition managed_diagnostics.hpp:134
bool observerFailed
The observer threw while receiving this error.
Definition managed_diagnostics.hpp:139
bool contextsTruncated
Context count or label byte budget truncated the trace.
Definition managed_diagnostics.hpp:135
bool contextUnavailable
Context allocation failed; error and origin survive.
Definition managed_diagnostics.hpp:136
Original error plus independent runner/restoration and cleanup failures.
Definition managed_diagnostics.hpp:62
std::shared_ptr< const SceneResourceError > sceneResource
Shared immutable runtime scene source, category and position; copies allocate no memory....
Definition managed_diagnostics.hpp:90
std::optional< TextResourceError > resource
Original resource lookup category, when present.
Definition managed_diagnostics.hpp:70
std::optional< SourceError > source
Exact window-source admission/read/delivery failure.
Definition managed_diagnostics.hpp:97
std::optional< BackgroundError > background
Exact executor admission cause when an async request fails.
Definition managed_diagnostics.hpp:94
std::optional< TreeError > cleanup
Independent failure while retiring the subtree.
Definition managed_diagnostics.hpp:68
std::shared_ptr< const DocumentOperationFailure > document
Optional owning document source/decoder detail; allocation failures retain the scalar cause.
Definition managed_diagnostics.hpp:99
ManagedPhase phase
First failing managed operation.
Definition managed_diagnostics.hpp:63
std::optional< SearchError > search
Exact bounded choice/search provider failure.
Definition managed_diagnostics.hpp:95
std::shared_ptr< const std::string > styleSource
Immutable owning source identity, or empty when unavailable; never borrowed through an error message....
Definition managed_diagnostics.hpp:78
std::optional< PasswordFailure > password
Allocation-free protected editor cause, including independent security and cleanup failures.
Definition managed_diagnostics.hpp:92
std::optional< std::source_location > operationOrigin
Original entered operation site, before facade propagation.
Definition managed_diagnostics.hpp:84
bool setupStopped
A scoped short failure stopped subsequent setup/run after the current callback returned.
Definition managed_diagnostics.hpp:86
std::optional< std::source_location > registrationOrigin
Static registration identity for a shortcut action failure; never a borrowed source view.
Definition managed_diagnostics.hpp:81
std::optional< ShortcutError > shortcut
Exact shortcut syntax/value cause and owned offset, when present.
Definition managed_diagnostics.hpp:79
std::optional< ApplicationError > application
Runner error, including terminal restoration.
Definition managed_diagnostics.hpp:67
const char * operation
Library static-storage operation label, independent of allocated diagnostic contexts.
Definition managed_diagnostics.hpp:82
std::optional< AsyncError > async
Exact coroutine/admission failure, independent of its tree bridge.
Definition managed_diagnostics.hpp:93
std::variant< TreeError, StyleError, ApplicationError > cause
Unformatted original error; StyleError messages follow their static-storage contract.
Definition managed_diagnostics.hpp:66
std::optional< PssFileError > file
Definition managed_diagnostics.hpp:73
std::optional< FileLogFailure > logFile
Original per-operation file cause and native error code.
Definition managed_diagnostics.hpp:100
NodeId node
Definition managed_diagnostics.hpp:64
std::optional< PssError > pss
Exact allocation-free PSS failure, including its owned subject and source position.
Definition managed_diagnostics.hpp:72
detail::ManagedErrorReceipt reportReceipt
Definition managed_diagnostics.hpp:87
std::optional< TextError > text
Original text-validation category and byte offset, when present.
Definition managed_diagnostics.hpp:69
const char * execution
Library static-storage facade boundary label; does not replace the original phase.
Definition managed_diagnostics.hpp:85
std::optional< NumericError > numeric
Exact finite-value, range, step or numeric-source conflict cause.
Definition managed_diagnostics.hpp:96
Owning identity, independent of addresses; zero is never a live identity.
Definition widget_types.hpp:15