refactor(api): replace throw statements with Result<T> in public headers#675
Merged
Merged
Conversation
Migrate public API error handling from exceptions to Result<T> pattern for v1.0 API stability. All throw statements in public headers are now replaced with common::Result<T> or common::VoidResult returns. Changes: - cancellation_token: rename throw_if_cancelled() to check_cancelled() returning VoidResult - enhanced_cancellation_token: same rename + update cancellation_scope - cancellable_future<R>: get() returns Result<R>, get_for() returns Result<optional<R>> - cancellable_future<void>: get() returns VoidResult, get_for() returns Result<bool> - thread_pool::submit_wait_any(): returns Result<R> instead of throwing on empty input - Update all affected tests to use Result-based assertions Closes #671
5 tasks
Contributor
📊 Performance Benchmark ResultsPerformance Benchmark ReportNo benchmark data available. ℹ️ No baseline reference availableThis is the first benchmark run or baseline file is missing. |
This was referenced Apr 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Summary
Replace all
throwstatements in public API headers withcommon::Result<T>orcommon::VoidResultreturn types, ensuring consistent error handling before the v1.0 API freeze.Change Type
Affected Components
include/kcenon/thread/core/cancellation_token.h—throw_if_cancelled()→check_cancelled()returningVoidResultinclude/kcenon/thread/core/enhanced_cancellation_token.h— same rename +cancellation_scope::check_cancelled()return typeinclude/kcenon/thread/core/cancellable_future.h—get()andget_for()return Result typesinclude/kcenon/thread/core/thread_pool_impl.h—submit_wait_any()returnsResult<R>include/kcenon/thread/core/thread_pool.h— declaration updatecore/sync/include/cancellation_token.h— module build copy syncWhy
Related Issues
Motivation
error_handling.hprovides comprehensivemake_error_result<T>()infrastructure but it was not applied in all public methodsWhere
Files Changed
include/kcenon/thread/core/core/sync/include/src/core/tests/unit/API Changes
cancellation_token::throw_if_cancelled()void(throws)check_cancelled()returnsVoidResultenhanced_cancellation_token::throw_if_cancelled()void(throws)check_cancelled()returnsVoidResultcancellation_scope::check_cancelled()void(throws)VoidResultcancellable_future<R>::get()R(throws)common::Result<R>cancellable_future<R>::get_for()optional<R>(throws)common::Result<optional<R>>cancellable_future<void>::get()void(throws)common::VoidResultcancellable_future<void>::get_for()bool(throws)common::Result<bool>thread_pool::submit_wait_any()R(throws)common::Result<R>How
Implementation Details
throwsite mapped to appropriateerror_codefromerror_handling.hcommon::Result<T>wrapping both cancellation errors and future exceptionsstd::future::get()exceptions caught and converted toerror_code::job_execution_failedEXPECT_THROWtoEXPECT_TRUE(result.is_err())patternTesting Done
LifecycleControllerTest.InitialStateIsCreated)Breaking Changes
throw_if_cancelled()renamed tocheck_cancelled()(both token types)cancellable_future::get()return type changed fromRtocommon::Result<R>cancellable_future::get_for()return type changedthread_pool::submit_wait_any()return type changed fromRtocommon::Result<R>Test Plan
cmake --preset debug && cmake --build build-debugcd build-debug && ctest --output-on-failurethrowin public headers:grep -rn '\bthrow\b' include/kcenon/thread/core/