Skip to content

refactor(error): complete Result<T> migration in bridge/adapter layer#962

Merged
kcenon merged 1 commit intodevelopfrom
fix/issue-957-result-migration
Apr 13, 2026
Merged

refactor(error): complete Result<T> migration in bridge/adapter layer#962
kcenon merged 1 commit intodevelopfrom
fix/issue-957-result-migration

Conversation

@kcenon
Copy link
Copy Markdown
Owner

@kcenon kcenon commented Apr 13, 2026

What

Summary

Replace all 15 remaining throw statements in src/ with Result factory patterns,
completing the exception-to-Result migration for the internal implementation layer.

Change Type

  • Refactor (no functional changes for success paths)

Why

Related Issues

Motivation

Public APIs were already migrated to Result in PR #952, but internal code still used
exceptions. This created inconsistency where public APIs return Result but internal
calls could throw, leading to unhandled exception risk.

Where

Files Changed (14 files, +194/-112 lines)

Area Files Throws Removed
Bridges observability_bridge.cpp/.h, thread_pool_bridge.cpp/.h 7
Adapters thread_system_adapter.cpp/.h, thread_pool_adapters.h 5
Protocol dtls_socket.cpp/.h 2
Utility message_validator.h 1
Call sites secure_messaging_udp_client/server.cpp (updated)
Tests test_input_validation.cpp, message_validator_extended_test.cpp (updated)

How

Migration Patterns Applied

  1. Constructor -> Factory: Throwing constructors replaced with static create() returning Result<shared_ptr<T>>
  2. Lambda throws -> set_exception: Thread pool lambda throws replaced with promise::set_exception(make_exception_ptr(...)) to propagate errors through futures without throw
  3. Throwing validator -> Result return: validate_size_or_throw replaced with validate_size returning validation_result enum

Verification

  • grep -rn "throw " src/ returns zero matches (excluding comments)
  • All call sites updated to handle Result returns
  • Tests updated to use new non-throwing APIs

Test Plan

  • All existing tests pass (success paths unchanged)
  • Updated validator tests verify Result-based API
  • No regressions on all CI platforms

Breaking Changes

  • dtls_socket constructor is now private; use dtls_socket::create() factory
  • validate_size_or_throw removed; use validate_size() returning validation_result
  • Bridge/adapter constructors now private; use ::create() factories

Replace all 15 remaining throw statements in src/ with Result<T>
factory patterns and error returns:

Bridges (7 throws removed):
- ObservabilityBridge: constructor -> create() factory, from_common_system() returns Result
- ThreadPoolBridge: create() factory, from_thread_system/from_common_system return Result

Adapters (4 throws removed):
- thread_system_pool_adapter: constructor -> create() factory
- network_to_common_thread_adapter: constructor -> create() factory,
  lambda throws replaced with promise::set_exception
- common_to_network_thread_adapter: constructor -> create() factory

Protocol (2 throws removed):
- dtls_socket: constructor -> create() factory, callers updated

Utility (1 throw removed):
- message_validator: validate_size_or_throw -> validate_size returning
  validation_result enum

Call sites updated:
- secure_messaging_udp_client/server: use dtls_socket::create()
- ThreadPoolBridge::from_common_system: use adapter::create()

Tests updated:
- test_input_validation.cpp: use validate_size() with result checks
- message_validator_extended_test.cpp: same

Closes #957
@kcenon kcenon merged commit 6cb1137 into develop Apr 13, 2026
1 of 5 checks passed
@kcenon kcenon deleted the fix/issue-957-result-migration branch April 13, 2026 15:00
kcenon added a commit that referenced this pull request Apr 13, 2026
Fix compilation errors from the Result<T> migration in PR #962:

- network_system_bridge.cpp: update from_thread_system(),
  from_common_system(), and with_custom() to handle Result returns
- thread_system_adapter.cpp: update create_default() and
  from_service_or_default() to use create() factory
kcenon added a commit that referenced this pull request Apr 13, 2026
Replace direct std::make_shared<dtls_socket> calls with
dtls_socket::create() factory method in secure_messaging_udp_client
and secure_messaging_udp_server. The constructor was made private
in the Result<T> migration (PR #962) but these call sites were missed.
kcenon added a commit that referenced this pull request Apr 13, 2026
* fix(bridge): update call sites for Result<T> factory migration

Fix compilation errors from the Result<T> migration in PR #962:

- network_system_bridge.cpp: update from_thread_system(),
  from_common_system(), and with_custom() to handle Result returns
- thread_system_adapter.cpp: update create_default() and
  from_service_or_default() to use create() factory

* fix(udp): update dtls_socket call sites for Result<T> factory migration

Replace direct std::make_shared<dtls_socket> calls with
dtls_socket::create() factory method in secure_messaging_udp_client
and secure_messaging_udp_server. The constructor was made private
in the Result<T> migration (PR #962) but these call sites were missed.

* fix(adapters): qualify Result types and update tests for factory pattern

Add ::kcenon::common:: namespace qualification to Result, error_codes,
and ok in common_to_network_thread_adapter::create(). Update tests to
use create() factory instead of private constructors for both adapter
classes.

* fix(test): update integration tests to use create() factory

Replace remaining std::make_shared calls with create() factory in
AdapterIntegrationTest for both network_to_common_thread_adapter
and common_to_network_thread_adapter.

* fix(test): update thread_pool_bridge tests for Result<T> factory migration

Replace direct constructor calls and std::make_shared with
ThreadPoolBridge::create() factory method. Update from_thread_system()
and from_common_system() tests to handle Result<T> return types.

* fix(test): update bridge tests for Result<T> factory migration

Update test_network_system_bridge.cpp and test_observability_bridge.cpp
to use create() factory methods instead of private constructors for
ThreadPoolBridge and ObservabilityBridge.

* fix(test): update dtls_socket tests for Result<T> factory migration

Replace direct constructor calls with dtls_socket::create() factory
method. Update null context test to check Result error instead of
expecting exception.

* fix(test): update server adapter test callback signatures to string_view

Update disconnection_callback_t, receive_callback_t, and
error_callback_t lambda parameters from legacy types to
std::string_view to match the updated i_protocol_server interface.

* fix(test): update client adapter test callback signatures

Remove session parameters from client adapter callback lambdas to match
simplified i_protocol_client interface where callbacks no longer receive
shared_ptr<i_session>.

* fix(test): update listener adapter tests for callback API changes

Update on_disconnected to on_disconnect and accept_callback_t
signature from string_view to unique_ptr<i_connection>.

* fix(validation): remove duplicate validate_size overload

Remove bool-returning validate_size that conflicted with
validation_result-returning version. Update test assertions
to use validation_result comparisons.
kcenon added a commit that referenced this pull request Apr 15, 2026
* fix(bridge): update call sites for Result<T> factory migration

Fix compilation errors from the Result<T> migration in PR #962:

- network_system_bridge.cpp: update from_thread_system(),
  from_common_system(), and with_custom() to handle Result returns
- thread_system_adapter.cpp: update create_default() and
  from_service_or_default() to use create() factory

* fix(udp): update dtls_socket call sites for Result<T> factory migration

Replace direct std::make_shared<dtls_socket> calls with
dtls_socket::create() factory method in secure_messaging_udp_client
and secure_messaging_udp_server. The constructor was made private
in the Result<T> migration (PR #962) but these call sites were missed.

* fix(adapters): qualify Result types and update tests for factory pattern

Add ::kcenon::common:: namespace qualification to Result, error_codes,
and ok in common_to_network_thread_adapter::create(). Update tests to
use create() factory instead of private constructors for both adapter
classes.

* fix(test): update integration tests to use create() factory

Replace remaining std::make_shared calls with create() factory in
AdapterIntegrationTest for both network_to_common_thread_adapter
and common_to_network_thread_adapter.

* fix(test): update thread_pool_bridge tests for Result<T> factory migration

Replace direct constructor calls and std::make_shared with
ThreadPoolBridge::create() factory method. Update from_thread_system()
and from_common_system() tests to handle Result<T> return types.

* fix(test): update bridge tests for Result<T> factory migration

Update test_network_system_bridge.cpp and test_observability_bridge.cpp
to use create() factory methods instead of private constructors for
ThreadPoolBridge and ObservabilityBridge.

* fix(test): update dtls_socket tests for Result<T> factory migration

Replace direct constructor calls with dtls_socket::create() factory
method. Update null context test to check Result error instead of
expecting exception.

* fix(test): update server adapter test callback signatures to string_view

Update disconnection_callback_t, receive_callback_t, and
error_callback_t lambda parameters from legacy types to
std::string_view to match the updated i_protocol_server interface.

* fix(test): update client adapter test callback signatures

Remove session parameters from client adapter callback lambdas to match
simplified i_protocol_client interface where callbacks no longer receive
shared_ptr<i_session>.

* fix(test): update listener adapter tests for callback API changes

Update on_disconnected to on_disconnect and accept_callback_t
signature from string_view to unique_ptr<i_connection>.

* fix(validation): remove duplicate validate_size overload

Remove bool-returning validate_size that conflicted with
validation_result-returning version. Update test assertions
to use validation_result comparisons.

* fix(network): correct include path for secure_tcp_socket.h

The header was using 'kcenon/network/internal/tcp/secure_tcp_socket.h'
which does not exist under any include directory. The actual file
resolves via the src/ include root as 'internal/tcp/secure_tcp_socket.h'.

* fix(network): restore canonical include path and fix internal_include symlink

Revert secure_session.h include path back to the canonical
'kcenon/network/internal/tcp/secure_tcp_socket.h' which resolves
via the internal_include symlink created at CMake configure time.

Add COPY_ON_ERROR to file(CREATE_LINK) so the symlink falls back to
a directory copy on platforms where symbolic links require elevated
privileges (e.g. Windows CI without Developer Mode).

* docs: fix 60+ broken links, unify toolchain versions, sanitize paths

Applied fixes from DOC_REVIEW_REPORT.md across 52 markdown files:

Security / portability:
- Replaced 11 committed absolute /Users/raphaelshin/... paths in
  docs/advanced/MIGRATION.md with repository-relative paths.

Path-scoping fixes (inter-file):
- Corrected ~30 bare filename references (TLS_SETUP_GUIDE.md,
  TROUBLESHOOTING.md, API_REFERENCE.md, BUILD.md, UDP_SUPPORT.md,
  LOAD_TEST_GUIDE.md, OPERATIONS.md) to include docs/guides/ or
  docs/advanced/ prefix as appropriate.
- Fixed wrong relative depth from docs/integration/ for ECOSYSTEM
  and external-repo references.

Toolchain version unification (authoritative: CMakeLists.txt + vcpkg.json):
- CMake: 3.16 -> 3.20 across all docs and examples.
- Compiler: normalized to GCC 13+, Clang 17+, MSVC 2022+,
  Apple Clang 14+ (removed inconsistent GCC 9+/10+/11+, Clang 10+/12+/14+
  claims from README.kr.md, BUILD[.kr].md, CONTRIBUTING[.kr].md,
  PRODUCTION_QUALITY[.kr].md, PROJECT_STRUCTURE[.kr].md, FEATURES.md,
  LOAD_TEST_GUIDE.md, QUICK_START[.kr].md, MIGRATION.md).
- ASIO: standardized to standalone ASIO 1.30.2+, explicitly noting
  Boost.ASIO is NOT supported (was contradictory: some docs allowed
  Boost.ASIO while CMake + CI reject it).
- Updated CHANGELOG version support matrix to include 1.5.0 as Current
  with CMake 3.20.

Anchor and TOC repairs:
- Trimmed 34-entry stale TOC in
  docs/implementation/01-architecture-and-components.md to only include
  sections that actually exist; marked unwritten sections with TODO.
- Fixed underscored anchors in docs/UNIFIED_API_GUIDE.md (i_transport,
  i_connection, i_listener).
- Fixed broken ../INTEGRATION.md link in ARCHITECTURE_OVERVIEW.md and
  empty docs/ link in CHANGELOG[.kr].md.

Missing targets:
- Replaced references to unwritten files (IMPROVEMENTS.md,
  CODING_STYLE_RULES.md, MIGRATION_GUIDE.md, MIGRATION_KO.md,
  DESIGN_DECISIONS.kr.md, GRPC_GUIDE.kr.md, README.kr.md siblings for
  implementation/ parts 1-4, with-thread-system.md, with-database-system.md,
  api/, architecture/, security/, performance/OPTIMIZATION.md,
  WEBSOCKET_IMPLEMENTATION_PLAN.md, examples/unified/,
  examples/network/, ECOSYSTEM_OVERVIEW.kr.md) with TODO markers plus
  the closest existing canonical doc.

SSOT deduplication:
- Integration Guide SSOT collision: kept docs/INTEGRATION.md canonical,
  demoted docs/INTEGRATION.kr.md to Korean translation marker, demoted
  docs/integration/README.md to per-system guide index.
- network-core/README.md demoted to pointer; libs/network-core/README.md
  remains canonical (matches active CMake target).
- Root CHANGELOG.md annotated as mirror of docs/CHANGELOG.md SSOT.

Bidirectional cross-references (Phase 3):
- Added "See Also" footers to ADR-001/002/003 linking to
  DESIGN_DECISIONS.md and siblings.
- Added tracing / performance xrefs in integration/with-monitoring.md.
- Added DTLS xref in guides/TLS_SETUP_GUIDE.md.
- Expanded docs/README.md registry to include ECOSYSTEM.md and
  GETTING_STARTED.md (previously orphaned).

Other fixes:
- Removed two stray bare ``` fences each in docs/API_REFERENCE_FACADES.md
  (3 total) and docs/API_REFERENCE_PROTOCOLS.md (1) that corrupted
  markdown parsing.
- Checked in DOC_REVIEW_REPORT.md as reference.

Counts: 11 absolute-path sanitizations, ~30 path-scoping corrections,
~25 compiler/CMake/ASIO alignments, 4 SSOT clarifications,
7 bidirectional xref additions, 4 code-fence repairs, 34 dangling TOC
entries resolved, ~20 missing-target TODOs inserted.

Skipped:
- Korean (.kr.md) content translation sync (out of scope: large).
- API/manifest version bumps (no code change requested).
- Content review of docs/advanced/MIGRATION.md beyond path sanitization.

* docs: add post-fix re-validation report
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant