Skip to content

refactor(error): migrate make_error call sites to typed error codes (Issue #230)#236

Merged
kcenon merged 3 commits into
mainfrom
refactor/issue-230-migrate-make-error-to-typed-codes
Feb 13, 2026
Merged

refactor(error): migrate make_error call sites to typed error codes (Issue #230)#236
kcenon merged 3 commits into
mainfrom
refactor/issue-230-migrate-make-error-to-typed-codes

Conversation

@kcenon

@kcenon kcenon commented Feb 13, 2026

Copy link
Copy Markdown
Owner

Closes #230

Summary

  • Migrated all make_error/error_info call sites across 32 files to use messaging_error_category typed error codes via make_typed_error_code()
  • Replaced #include <kcenon/messaging/error/error_codes.h> with #include <kcenon/messaging/error/messaging_error_category.h> in all migrated files
  • Updated message_serializer.h to use messaging-specific error codes (message_serialization_failed, message_deserialization_failed, invalid_payload, not_supported) instead of generic common::error_codes
  • Updated test_message_bus.cpp to use messaging_error_category type alias for error code assertions
  • Fixed thread_pool_executor::worker_count() to return total workers (active + idle) instead of only active workers

Scope

Files Modified (32 total + 4 test fixes)

Core (5 files): message.cpp, message_bus.cpp, message_broker.cpp, message_queue.cpp, topic_router.cpp
Patterns (4 files): request_reply.cpp, event_streaming.cpp, message_pipeline.cpp, pub_sub.cpp
Backends (2 files): standalone_backend.cpp, integration_backend.cpp
Adapters (4 files): http_transport.h/.cpp, websocket_transport.h/.cpp
Task (11 files): task.cpp, scheduler.cpp, cron_parser.cpp, worker_pool.cpp, monitor.cpp, memory_result_backend.cpp, task_queue.cpp, task_system.cpp, task_client.cpp, task_context.cpp, async_result.cpp
Headers (5 files): message_serializer.h, event_bridge.h, executor_adapter.h, task_event_bridge.h, task_handler.h
Tests (4 files): test_message_bus.cpp, test_result_backend.cpp, test_async_result.cpp, test_worker_pool.cpp

Not migrated (intentional)

  • Call sites using common::error::codes::common_errors::* (e.g., invalid_argument, not_found) remain unchanged as they represent genuine common system errors, not messaging-specific errors

Migration Pattern

// Before
return common::make_error<T>(error::code_name, "message", "source");
return common::error_info(error::code_name, "message");

// After
return common::Result<T>::err(make_typed_error_code(messaging_error_category::code_name));

Test Plan

  • CI build passes on all platforms (12/12 checks pass)
  • All existing unit tests pass (error code numeric values are identical)
  • No remaining messaging/error/error_codes.h includes in migrated files

…Issue #230)

Replace all make_error/error_info call sites across 32 files to use
messaging_error_category typed error codes via make_typed_error_code().

- Core: message.cpp, message_bus.cpp, message_broker.cpp, message_queue.cpp, topic_router.cpp
- Patterns: request_reply.cpp, event_streaming.cpp, message_pipeline.cpp, pub_sub.cpp
- Backends: standalone_backend.cpp, integration_backend.cpp
- Adapters: http_transport.h/.cpp, websocket_transport.h/.cpp
- Task: task.cpp, scheduler.cpp, cron_parser.cpp, worker_pool.cpp, and 7 more
- Serialization: message_serializer.h
- Integration: event_bridge.h, executor_adapter.h, task_event_bridge.h, task_handler.h
- Tests: test_message_bus.cpp updated to use messaging_error_category type alias
@kcenon

kcenon commented Feb 13, 2026

Copy link
Copy Markdown
Owner Author

CI/CD Failure Analysis

Analysis Time: 2026-02-14
Attempt: #1

Failed Workflows

Workflow Job Step Status
CI windows-2022 / msvc Run tests Failed

Root Cause Analysis

Primary Error: Test assertions checking error message strings fail after migrating to typed error codes.

The migration from make_error<T>(code, "Custom message") to Result<T>::err(make_typed_error_code(messaging_error_category::code)) changes how error messages are generated. Previously, each call site provided a custom string. Now, the error category provides standardized messages via its message(int code) method.

Failed Tests (5):

Test File Issue
MemoryResultBackendTest.WaitForResultFailure test_result_backend.cpp:216 message.find("Something went wrong") fails
MemoryResultBackendTest.WaitForResultTimeout test_result_backend.cpp:231 message.find("Timeout") fails
AsyncResultTest.GetResult_InvalidHandle test_async_result.cpp:156 Error message equality check fails
WorkerPoolTest.TaskTimeoutErrorMessage test_worker_pool.cpp:911 message.find("timed out") fails
StandaloneBackendTest.ZeroThreads test_standalone_backend.cpp:163 Possibly pre-existing

Proposed Fix

Update test assertions to match new typed error code messages from messaging_error_category::message(), or change assertions to verify error codes instead of message strings.

Next Steps

  • Read failing test files and corresponding source changes
  • Update test assertions to match new error messages
  • Push fix and monitor CI

Automated failure analysis - Attempt #1

Update test assertions to match new standardized error messages
from messaging_error_category instead of custom per-call-site strings.

- test_result_backend: "Something went wrong" -> "Task execution failed"
- test_result_backend: "Timeout" -> "Task timeout"
- test_async_result: "Invalid async_result handle" -> "Task not found"
- test_worker_pool: "timed out" -> "Task timeout"
thread_pool_executor::worker_count() was calling get_active_worker_count()
which only returns workers currently executing tasks. When no tasks are
submitted, all workers are idle and the count returns 0. This caused
StandaloneBackendTest.ZeroThreads to fail on Windows MSVC.

Fix: sum active + idle workers to return the total worker count.
@kcenon

kcenon commented Feb 13, 2026

Copy link
Copy Markdown
Owner Author

CI/CD Failure Analysis - Attempt #2

Previous Attempt Result: 4/5 test failures fixed, 1 remaining
Previous Fix Applied: Updated error message assertions in test_result_backend.cpp, test_async_result.cpp, test_worker_pool.cpp

New Failure Analysis

Workflow Job Step Previous Status Current Status
Build & Test windows-2022 / msvc Run tests 5 failures 1 failure

What Changed

Previous Fix:

  • Updated 4 test assertions to match new typed error code messages

Remaining Failure:

  • StandaloneBackendTest.ZeroThreads - unrelated to error code migration

Root Cause

Error:

Expected: (executor->worker_count()) > (0), actual: 0 vs 0

Analysis:
thread_pool_executor::worker_count() was calling pool_->get_active_worker_count() which only returns workers currently executing tasks. Since the ZeroThreads test doesn't submit any tasks after initialization, all workers are idle. On Windows MSVC, the timing is such that get_active_worker_count() correctly returns 0.

The fix sums get_active_worker_count() + get_idle_worker_count() to return the total worker count, which is what the test expects.

Fix Applied

Issue Solution Files Affected
worker_count() returns 0 when no tasks are running Sum active + idle workers for total count src/impl/backends/standalone_backend.cpp

Commits

  1. c2dd7a49 - refactor(error): migrate make_error call sites to typed error codes
  2. 17199406 - fix(test): update error message assertions for typed error codes
  3. 48a18cdd - fix(backend): return total worker count instead of only active workers

Automated failure analysis - Attempt #2 of 3

@kcenon kcenon merged commit 2589362 into main Feb 13, 2026
12 checks passed
@kcenon kcenon deleted the refactor/issue-230-migrate-make-error-to-typed-codes branch February 13, 2026 23:41
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.

[Refactor] Migrate make_error call sites to typed error codes

1 participant