daemon: adopt HandlerResult<T> — real error codes from handlers (contracts/ 1.4.0)

Rebased onto main at 1.4.0. The regenerated Dispatcher returns
HandlerResult<T> = expected<T, HandlerError{code, message, data}>
(ADR 0014); the covariant-return break on all 39 overrides is the swap
predicted in daemon/docs/proto-requests-m1.md P1.

- dispatcher.hpp/.cpp: Result<T> -> HandlerResult<T> on every override;
  not_implemented() now returns HandlerError{InternalError, ...} rather
  than a ParseError forwarded as -32603.
- download.get: returns -32010 TaskNotFound with data.taskId. Not a
  placeholder — with no store, every id is genuinely not-found, which
  is the real answer for contracts/ fixture download.get.not-found. It
  becomes a store lookup when store/ is wired in.
- uds_roundtrip: the -32603-collapse guard is now a -32010 + data.taskId
  assertion, the regression guard the P1 note promised.

download.add (-32011) and download.probe (-32013) stay InternalError
until they have real bodies (canonicalization / probe); they get their
fixture codes when that logic lands.

All 24 tests green; uds_roundtrip TSan-clean.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Upd9WhG9oppieig5nRDLig
This commit is contained in:
2026-09-10 15:31:00 +04:00
co-authored by Claude Sonnet 5
parent 4b279e8271
commit e585113daf
3 changed files with 97 additions and 90 deletions
+51 -46
View File
@@ -6,12 +6,13 @@ namespace proto = velox::proto;
namespace {
// The generated Result<T> carries only proto::ParseError, whose {path, message} the
// generated dispatch() forwards as -32603 data. Until P1 (daemon/docs/proto-requests-m1.md)
// gives handlers a real error channel, an unimplemented method says so plainly here.
// A method whose body arrives with the store / scheduler. Answers -32603 with a clear
// message through the generated HandlerError channel (contracts/ 1.4.0, ADR 0014).
template <class T>
proto::Result<T> not_implemented(const char* method) {
return std::unexpected(proto::ParseError{method, "not implemented in this build"});
proto::HandlerResult<T> not_implemented(const char* method) {
return std::unexpected(proto::HandlerError{
proto::ErrorCode::InternalError,
std::string("not implemented in this build: ") + method});
}
} // namespace
@@ -20,24 +21,24 @@ proto::Result<T> not_implemented(const char* method) {
// Kept as explicit stubs so a direct dispatch() caller (a test, a future in-process client)
// gets a clear answer rather than undefined behaviour from a missing override.
proto::Result<proto::SessionHelloResult>
proto::HandlerResult<proto::SessionHelloResult>
VeloxDispatcher::on_session_hello(const proto::SessionHelloParams&) {
return not_implemented<proto::SessionHelloResult>("session.hello");
}
proto::Result<proto::SessionPairResult>
proto::HandlerResult<proto::SessionPairResult>
VeloxDispatcher::on_session_pair(const proto::SessionPairParams&) {
return not_implemented<proto::SessionPairResult>("session.pair");
}
proto::Result<proto::SessionSubscribeResult>
proto::HandlerResult<proto::SessionSubscribeResult>
VeloxDispatcher::on_session_subscribe(const proto::SessionSubscribeParams&) {
return not_implemented<proto::SessionSubscribeResult>("session.subscribe");
}
// --- download.list : an empty table, so a client can connect and render ---------------
proto::Result<proto::DownloadListResult>
proto::HandlerResult<proto::DownloadListResult>
VeloxDispatcher::on_download_list(const proto::DownloadListParams&) {
proto::DownloadListResult r;
r.total = 0;
@@ -46,141 +47,145 @@ VeloxDispatcher::on_download_list(const proto::DownloadListParams&) {
// --- everything else : not implemented until the store and scheduler land -------------
proto::Result<proto::CaptureRules>
proto::HandlerResult<proto::CaptureRules>
VeloxDispatcher::on_capture_getRules(const proto::CaptureGetRulesParams&) {
return not_implemented<proto::CaptureRules>("capture.getRules");
}
proto::Result<proto::CaptureOfferResult>
proto::HandlerResult<proto::CaptureOfferResult>
VeloxDispatcher::on_capture_offer(const proto::CaptureOfferParams&) {
return not_implemented<proto::CaptureOfferResult>("capture.offer");
}
proto::Result<proto::CategoryListResult>
proto::HandlerResult<proto::CategoryListResult>
VeloxDispatcher::on_category_list(const proto::CategoryListParams&) {
return not_implemented<proto::CategoryListResult>("category.list");
}
proto::Result<proto::CategoryRemoveResult>
proto::HandlerResult<proto::CategoryRemoveResult>
VeloxDispatcher::on_category_remove(const proto::CategoryRemoveParams&) {
return not_implemented<proto::CategoryRemoveResult>("category.remove");
}
proto::Result<proto::CategoryUpsertResult>
proto::HandlerResult<proto::CategoryUpsertResult>
VeloxDispatcher::on_category_upsert(const proto::CategoryUpsertParams&) {
return not_implemented<proto::CategoryUpsertResult>("category.upsert");
}
proto::Result<proto::DownloadAddResult>
proto::HandlerResult<proto::DownloadAddResult>
VeloxDispatcher::on_download_add(const proto::DownloadSpec&) {
return not_implemented<proto::DownloadAddResult>("download.add");
}
proto::Result<proto::DownloadAddBatchResult>
proto::HandlerResult<proto::DownloadAddBatchResult>
VeloxDispatcher::on_download_addBatch(const proto::DownloadAddBatchParams&) {
return not_implemented<proto::DownloadAddBatchResult>("download.addBatch");
}
proto::Result<proto::BulkTaskResult>
proto::HandlerResult<proto::BulkTaskResult>
VeloxDispatcher::on_download_cancel(const proto::DownloadCancelParams&) {
return not_implemented<proto::BulkTaskResult>("download.cancel");
}
proto::Result<proto::TaskDetail>
VeloxDispatcher::on_download_get(const proto::DownloadGetParams&) {
return not_implemented<proto::TaskDetail>("download.get");
proto::HandlerResult<proto::TaskDetail>
VeloxDispatcher::on_download_get(const proto::DownloadGetParams& params) {
// No store is wired yet, so no task exists and every id is genuinely not-found. This
// is the real -32010 answer (contracts/ error fixture download.get.not-found), not a
// placeholder; it becomes a store lookup when store/ is wired in.
return std::unexpected(proto::HandlerError{proto::ErrorCode::TaskNotFound, "no such task",
nlohmann::json{{"taskId", params.taskId}}});
}
proto::Result<proto::BulkTaskResult>
proto::HandlerResult<proto::BulkTaskResult>
VeloxDispatcher::on_download_pause(const proto::DownloadPauseParams&) {
return not_implemented<proto::BulkTaskResult>("download.pause");
}
proto::Result<proto::DownloadProbeResult>
proto::HandlerResult<proto::DownloadProbeResult>
VeloxDispatcher::on_download_probe(const proto::DownloadProbeParams&) {
return not_implemented<proto::DownloadProbeResult>("download.probe");
}
proto::Result<proto::DownloadProvideAuthResult>
proto::HandlerResult<proto::DownloadProvideAuthResult>
VeloxDispatcher::on_download_provideAuth(const proto::DownloadProvideAuthParams&) {
return not_implemented<proto::DownloadProvideAuthResult>("download.provideAuth");
}
proto::Result<proto::DownloadRefreshUrlResult>
proto::HandlerResult<proto::DownloadRefreshUrlResult>
VeloxDispatcher::on_download_refreshUrl(const proto::DownloadRefreshUrlParams&) {
return not_implemented<proto::DownloadRefreshUrlResult>("download.refreshUrl");
}
proto::Result<proto::DownloadRemoveResult>
proto::HandlerResult<proto::DownloadRemoveResult>
VeloxDispatcher::on_download_remove(const proto::DownloadRemoveParams&) {
return not_implemented<proto::DownloadRemoveResult>("download.remove");
}
proto::Result<proto::BulkTaskResult>
proto::HandlerResult<proto::BulkTaskResult>
VeloxDispatcher::on_download_resume(const proto::DownloadResumeParams&) {
return not_implemented<proto::BulkTaskResult>("download.resume");
}
proto::Result<proto::BulkTaskResult>
proto::HandlerResult<proto::BulkTaskResult>
VeloxDispatcher::on_download_start(const proto::DownloadStartParams&) {
return not_implemented<proto::BulkTaskResult>("download.start");
}
proto::Result<proto::TaskSummary>
proto::HandlerResult<proto::TaskSummary>
VeloxDispatcher::on_download_update(const proto::DownloadUpdateParams&) {
return not_implemented<proto::TaskSummary>("download.update");
}
proto::Result<proto::GrabberHarvestResult>
proto::HandlerResult<proto::GrabberHarvestResult>
VeloxDispatcher::on_grabber_harvest(const proto::GrabberHarvestParams&) {
return not_implemented<proto::GrabberHarvestResult>("grabber.harvest");
}
proto::Result<proto::GrabberStartResult>
proto::HandlerResult<proto::GrabberStartResult>
VeloxDispatcher::on_grabber_start(const proto::GrabberStartParams&) {
return not_implemented<proto::GrabberStartResult>("grabber.start");
}
proto::Result<proto::GrabberStatusResult>
proto::HandlerResult<proto::GrabberStatusResult>
VeloxDispatcher::on_grabber_status(const proto::GrabberStatusParams&) {
return not_implemented<proto::GrabberStatusResult>("grabber.status");
}
proto::Result<proto::Limiter> VeloxDispatcher::on_limiter_get(const proto::LimiterGetParams&) {
proto::HandlerResult<proto::Limiter> VeloxDispatcher::on_limiter_get(const proto::LimiterGetParams&) {
return not_implemented<proto::Limiter>("limiter.get");
}
proto::Result<proto::Limiter> VeloxDispatcher::on_limiter_set(const proto::Limiter&) {
proto::HandlerResult<proto::Limiter> VeloxDispatcher::on_limiter_set(const proto::Limiter&) {
return not_implemented<proto::Limiter>("limiter.set");
}
proto::Result<proto::MediaAddVariantResult>
proto::HandlerResult<proto::MediaAddVariantResult>
VeloxDispatcher::on_media_addVariant(const proto::MediaAddVariantParams&) {
return not_implemented<proto::MediaAddVariantResult>("media.addVariant");
}
proto::Result<proto::MediaListVariantsResult>
proto::HandlerResult<proto::MediaListVariantsResult>
VeloxDispatcher::on_media_listVariants(const proto::MediaListVariantsParams&) {
return not_implemented<proto::MediaListVariantsResult>("media.listVariants");
}
proto::Result<proto::QueueListResult>
proto::HandlerResult<proto::QueueListResult>
VeloxDispatcher::on_queue_list(const proto::QueueListParams&) {
return not_implemented<proto::QueueListResult>("queue.list");
}
proto::Result<proto::QueueReorderResult>
proto::HandlerResult<proto::QueueReorderResult>
VeloxDispatcher::on_queue_reorder(const proto::QueueReorderParams&) {
return not_implemented<proto::QueueReorderResult>("queue.reorder");
}
proto::Result<proto::QueueStartResult>
proto::HandlerResult<proto::QueueStartResult>
VeloxDispatcher::on_queue_start(const proto::QueueStartParams&) {
return not_implemented<proto::QueueStartResult>("queue.start");
}
proto::Result<proto::QueueStopResult>
proto::HandlerResult<proto::QueueStopResult>
VeloxDispatcher::on_queue_stop(const proto::QueueStopParams&) {
return not_implemented<proto::QueueStopResult>("queue.stop");
}
proto::Result<proto::QueueUpsertResult>
proto::HandlerResult<proto::QueueUpsertResult>
VeloxDispatcher::on_queue_upsert(const proto::QueueUpsertParams&) {
return not_implemented<proto::QueueUpsertResult>("queue.upsert");
}
proto::Result<proto::RulesListResult>
proto::HandlerResult<proto::RulesListResult>
VeloxDispatcher::on_rules_list(const proto::RulesListParams&) {
return not_implemented<proto::RulesListResult>("rules.list");
}
proto::Result<proto::RulesUpsertResult>
proto::HandlerResult<proto::RulesUpsertResult>
VeloxDispatcher::on_rules_upsert(const proto::RulesUpsertParams&) {
return not_implemented<proto::RulesUpsertResult>("rules.upsert");
}
proto::Result<proto::ScheduleGetResult>
proto::HandlerResult<proto::ScheduleGetResult>
VeloxDispatcher::on_schedule_get(const proto::ScheduleGetParams&) {
return not_implemented<proto::ScheduleGetResult>("schedule.get");
}
proto::Result<proto::ScheduleSetResult>
proto::HandlerResult<proto::ScheduleSetResult>
VeloxDispatcher::on_schedule_set(const proto::ScheduleSetParams&) {
return not_implemented<proto::ScheduleSetResult>("schedule.set");
}
proto::Result<proto::SettingsGetResult>
proto::HandlerResult<proto::SettingsGetResult>
VeloxDispatcher::on_settings_get(const proto::SettingsGetParams&) {
return not_implemented<proto::SettingsGetResult>("settings.get");
}
proto::Result<proto::SettingsSetResult>
proto::HandlerResult<proto::SettingsSetResult>
VeloxDispatcher::on_settings_set(const proto::SettingsSetParams&) {
return not_implemented<proto::SettingsSetResult>("settings.set");
}
+39 -39
View File
@@ -21,82 +21,82 @@ namespace velox::daemon::rpc {
class VeloxDispatcher final : public velox::proto::Dispatcher {
public:
velox::proto::Result<velox::proto::CaptureRules>
velox::proto::HandlerResult<velox::proto::CaptureRules>
on_capture_getRules(const velox::proto::CaptureGetRulesParams&) override;
velox::proto::Result<velox::proto::CaptureOfferResult>
velox::proto::HandlerResult<velox::proto::CaptureOfferResult>
on_capture_offer(const velox::proto::CaptureOfferParams&) override;
velox::proto::Result<velox::proto::CategoryListResult>
velox::proto::HandlerResult<velox::proto::CategoryListResult>
on_category_list(const velox::proto::CategoryListParams&) override;
velox::proto::Result<velox::proto::CategoryRemoveResult>
velox::proto::HandlerResult<velox::proto::CategoryRemoveResult>
on_category_remove(const velox::proto::CategoryRemoveParams&) override;
velox::proto::Result<velox::proto::CategoryUpsertResult>
velox::proto::HandlerResult<velox::proto::CategoryUpsertResult>
on_category_upsert(const velox::proto::CategoryUpsertParams&) override;
velox::proto::Result<velox::proto::DownloadAddResult>
velox::proto::HandlerResult<velox::proto::DownloadAddResult>
on_download_add(const velox::proto::DownloadSpec&) override;
velox::proto::Result<velox::proto::DownloadAddBatchResult>
velox::proto::HandlerResult<velox::proto::DownloadAddBatchResult>
on_download_addBatch(const velox::proto::DownloadAddBatchParams&) override;
velox::proto::Result<velox::proto::BulkTaskResult>
velox::proto::HandlerResult<velox::proto::BulkTaskResult>
on_download_cancel(const velox::proto::DownloadCancelParams&) override;
velox::proto::Result<velox::proto::TaskDetail>
velox::proto::HandlerResult<velox::proto::TaskDetail>
on_download_get(const velox::proto::DownloadGetParams&) override;
velox::proto::Result<velox::proto::DownloadListResult>
velox::proto::HandlerResult<velox::proto::DownloadListResult>
on_download_list(const velox::proto::DownloadListParams&) override;
velox::proto::Result<velox::proto::BulkTaskResult>
velox::proto::HandlerResult<velox::proto::BulkTaskResult>
on_download_pause(const velox::proto::DownloadPauseParams&) override;
velox::proto::Result<velox::proto::DownloadProbeResult>
velox::proto::HandlerResult<velox::proto::DownloadProbeResult>
on_download_probe(const velox::proto::DownloadProbeParams&) override;
velox::proto::Result<velox::proto::DownloadProvideAuthResult>
velox::proto::HandlerResult<velox::proto::DownloadProvideAuthResult>
on_download_provideAuth(const velox::proto::DownloadProvideAuthParams&) override;
velox::proto::Result<velox::proto::DownloadRefreshUrlResult>
velox::proto::HandlerResult<velox::proto::DownloadRefreshUrlResult>
on_download_refreshUrl(const velox::proto::DownloadRefreshUrlParams&) override;
velox::proto::Result<velox::proto::DownloadRemoveResult>
velox::proto::HandlerResult<velox::proto::DownloadRemoveResult>
on_download_remove(const velox::proto::DownloadRemoveParams&) override;
velox::proto::Result<velox::proto::BulkTaskResult>
velox::proto::HandlerResult<velox::proto::BulkTaskResult>
on_download_resume(const velox::proto::DownloadResumeParams&) override;
velox::proto::Result<velox::proto::BulkTaskResult>
velox::proto::HandlerResult<velox::proto::BulkTaskResult>
on_download_start(const velox::proto::DownloadStartParams&) override;
velox::proto::Result<velox::proto::TaskSummary>
velox::proto::HandlerResult<velox::proto::TaskSummary>
on_download_update(const velox::proto::DownloadUpdateParams&) override;
velox::proto::Result<velox::proto::GrabberHarvestResult>
velox::proto::HandlerResult<velox::proto::GrabberHarvestResult>
on_grabber_harvest(const velox::proto::GrabberHarvestParams&) override;
velox::proto::Result<velox::proto::GrabberStartResult>
velox::proto::HandlerResult<velox::proto::GrabberStartResult>
on_grabber_start(const velox::proto::GrabberStartParams&) override;
velox::proto::Result<velox::proto::GrabberStatusResult>
velox::proto::HandlerResult<velox::proto::GrabberStatusResult>
on_grabber_status(const velox::proto::GrabberStatusParams&) override;
velox::proto::Result<velox::proto::Limiter>
velox::proto::HandlerResult<velox::proto::Limiter>
on_limiter_get(const velox::proto::LimiterGetParams&) override;
velox::proto::Result<velox::proto::Limiter> on_limiter_set(const velox::proto::Limiter&) override;
velox::proto::Result<velox::proto::MediaAddVariantResult>
velox::proto::HandlerResult<velox::proto::Limiter> on_limiter_set(const velox::proto::Limiter&) override;
velox::proto::HandlerResult<velox::proto::MediaAddVariantResult>
on_media_addVariant(const velox::proto::MediaAddVariantParams&) override;
velox::proto::Result<velox::proto::MediaListVariantsResult>
velox::proto::HandlerResult<velox::proto::MediaListVariantsResult>
on_media_listVariants(const velox::proto::MediaListVariantsParams&) override;
velox::proto::Result<velox::proto::QueueListResult>
velox::proto::HandlerResult<velox::proto::QueueListResult>
on_queue_list(const velox::proto::QueueListParams&) override;
velox::proto::Result<velox::proto::QueueReorderResult>
velox::proto::HandlerResult<velox::proto::QueueReorderResult>
on_queue_reorder(const velox::proto::QueueReorderParams&) override;
velox::proto::Result<velox::proto::QueueStartResult>
velox::proto::HandlerResult<velox::proto::QueueStartResult>
on_queue_start(const velox::proto::QueueStartParams&) override;
velox::proto::Result<velox::proto::QueueStopResult>
velox::proto::HandlerResult<velox::proto::QueueStopResult>
on_queue_stop(const velox::proto::QueueStopParams&) override;
velox::proto::Result<velox::proto::QueueUpsertResult>
velox::proto::HandlerResult<velox::proto::QueueUpsertResult>
on_queue_upsert(const velox::proto::QueueUpsertParams&) override;
velox::proto::Result<velox::proto::RulesListResult>
velox::proto::HandlerResult<velox::proto::RulesListResult>
on_rules_list(const velox::proto::RulesListParams&) override;
velox::proto::Result<velox::proto::RulesUpsertResult>
velox::proto::HandlerResult<velox::proto::RulesUpsertResult>
on_rules_upsert(const velox::proto::RulesUpsertParams&) override;
velox::proto::Result<velox::proto::ScheduleGetResult>
velox::proto::HandlerResult<velox::proto::ScheduleGetResult>
on_schedule_get(const velox::proto::ScheduleGetParams&) override;
velox::proto::Result<velox::proto::ScheduleSetResult>
velox::proto::HandlerResult<velox::proto::ScheduleSetResult>
on_schedule_set(const velox::proto::ScheduleSetParams&) override;
velox::proto::Result<velox::proto::SessionHelloResult>
velox::proto::HandlerResult<velox::proto::SessionHelloResult>
on_session_hello(const velox::proto::SessionHelloParams&) override;
velox::proto::Result<velox::proto::SessionPairResult>
velox::proto::HandlerResult<velox::proto::SessionPairResult>
on_session_pair(const velox::proto::SessionPairParams&) override;
velox::proto::Result<velox::proto::SessionSubscribeResult>
velox::proto::HandlerResult<velox::proto::SessionSubscribeResult>
on_session_subscribe(const velox::proto::SessionSubscribeParams&) override;
velox::proto::Result<velox::proto::SettingsGetResult>
velox::proto::HandlerResult<velox::proto::SettingsGetResult>
on_settings_get(const velox::proto::SettingsGetParams&) override;
velox::proto::Result<velox::proto::SettingsSetResult>
velox::proto::HandlerResult<velox::proto::SettingsSetResult>
on_settings_set(const velox::proto::SettingsSetParams&) override;
};
+7 -5
View File
@@ -148,17 +148,19 @@ void run() {
::close(c);
}
// --- download.get -> -32603 for now: documents the P1 codegen gap ---------------
// (proto-requests-m1.md P1: handlers cannot yet return -32010. When P1 lands this
// check flips to -32010 and is the regression guard for it.)
// --- download.get on an unknown id -> -32010, with data.taskId ------------------
// (contracts/ error fixture download.get.not-found; reachable now that 1.4.0 gave
// handlers the HandlerError channel — ADR 0014.)
{
const int c = connect_client(sock);
const std::string missing = "00000000-0000-4000-8000-000000000000";
const json reply = call(c, {{"jsonrpc", "2.0"},
{"id", 6},
{"method", "download.get"},
{"params", {{"taskId", "00000000-0000-4000-8000-000000000000"}}}});
{"params", {{"taskId", missing}}}});
CHECK(reply.contains("error"));
CHECK_EQ(reply["error"]["code"].get<int>(), -32603);
CHECK_EQ(reply["error"]["code"].get<int>(), -32010);
CHECK_EQ(reply["error"]["data"]["taskId"].get<std::string>(), missing);
::close(c);
}