DAEMON's daemon/docs/proto-requests-m1.md P1: velox::proto::Dispatcher's
on_* methods returned Result<T> = expected<T, ParseError>, and dispatch()
mapped every handler error to -32603 InternalError. A handler had no way to
return -32010 (download.get not-found), -32011 (download.add invalid-path)
or -32013 (probe-failed) with their data payloads -- three error fixtures a
conformant server must satisfy were unreachable, blocking DAEMON's
"conformance as a server" M1 DoD.
Two error channels now, kept separate on purpose:
- parse: Result<T> / ParseError -- dispatch() failing to turn the wire into
typed params. Always -32602, always structural.
- handler: HandlerResult<T> / HandlerError -- a handler deciding the request
can't be fulfilled. Carries any ErrorCode + message + free-form data.
struct HandlerError {
ErrorCode code{ErrorCode::InternalError}; // bare {} is a valid -32603
std::string message;
nlohmann::json data = nullptr; // straight into the error's data
};
template <class T> using HandlerResult = std::expected<T, HandlerError>;
dispatch()'s handler branch is now
make_error(id, r.error().code, r.error().message, r.error().data)
instead of a hard-coded InternalError. -32001/-32002/-32003 stay the server
layer's to raise around dispatch(), as DAEMON already does.
Verified end to end against the real dispatch() path: a handler returning
TaskNotFound/InvalidPath/ProbeFailed produces -32010/-32011/-32013 with the
data object intact, and a bare HandlerError{} still yields a clean -32603
with no data field. The `= nullptr` on the member (not `{nullptr}`) matters:
brace-init of nlohmann::json from nullptr is the array [null], not JSON null.
FixtureDispatcher regenerated to HandlerResult; conformance_main.cpp only
inspects dispatch()'s JSON and needed no change. TS side is untouched beyond
the version string -- no server Dispatcher is generated there.
P2 also handled: session.hello.version-mismatch's data.expected was a stale
"1.0.0"; now $any, with a note that the error-fixture compare is on `code`
only so a server echoing kProtocolVersion there is fine.
Version: minor, 1.3.0 -> 1.4.0. Wire is byte-identical (no schema, fixture,
or OpenRPC change) but every Dispatcher implementer must swap Result ->
HandlerResult on regen, and the bump is how lanes are told to. Not an ADR:
one lane consumes this binding, it's the one that asked, and the shape is
the one they proposed. Answered in contracts/proto-answers-daemon-m1.md.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012fgjnqFCS5h5L7gZTZo3rV
247 lines
10 KiB
C++
247 lines
10 KiB
C++
// ---------------------------------------------------------------------------
|
|
// GENERATED FILE — DO NOT EDIT.
|
|
//
|
|
// Source: contracts/schema/**
|
|
// Generator: contracts/codegen/gen_cpp.py
|
|
// Contract: v1.4.0
|
|
//
|
|
// Hand-editing this file is a merge blocker. Fix the schema and regenerate:
|
|
// python3 contracts/codegen/gen_cpp.py
|
|
// Only lane PROTO commits to contracts/.
|
|
// ---------------------------------------------------------------------------
|
|
|
|
#pragma once
|
|
|
|
#include "velox_proto.hpp"
|
|
|
|
#include <functional>
|
|
#include <string>
|
|
|
|
namespace velox::conformance {
|
|
|
|
/// Answers every method from its golden fixture, so the generated dispatch path
|
|
/// itself is under test: envelope, transport check, param parse, result serialise.
|
|
class FixtureDispatcher final : public proto::Dispatcher {
|
|
public:
|
|
/// `results` maps a method name to that method's golden result JSON.
|
|
explicit FixtureDispatcher(std::function<const nlohmann::json*(const std::string&)> results)
|
|
: results_(std::move(results)) {}
|
|
|
|
proto::HandlerResult<proto::CaptureRules> on_capture_getRules(const proto::CaptureGetRulesParams& params) override {
|
|
(void)params;
|
|
return golden<proto::CaptureRules>("capture.getRules");
|
|
}
|
|
|
|
proto::HandlerResult<proto::CaptureOfferResult> on_capture_offer(const proto::CaptureOfferParams& params) override {
|
|
(void)params;
|
|
return golden<proto::CaptureOfferResult>("capture.offer");
|
|
}
|
|
|
|
proto::HandlerResult<proto::CategoryListResult> on_category_list(const proto::CategoryListParams& params) override {
|
|
(void)params;
|
|
return golden<proto::CategoryListResult>("category.list");
|
|
}
|
|
|
|
proto::HandlerResult<proto::CategoryRemoveResult> on_category_remove(const proto::CategoryRemoveParams& params) override {
|
|
(void)params;
|
|
return golden<proto::CategoryRemoveResult>("category.remove");
|
|
}
|
|
|
|
proto::HandlerResult<proto::CategoryUpsertResult> on_category_upsert(const proto::CategoryUpsertParams& params) override {
|
|
(void)params;
|
|
return golden<proto::CategoryUpsertResult>("category.upsert");
|
|
}
|
|
|
|
proto::HandlerResult<proto::DownloadAddResult> on_download_add(const proto::DownloadSpec& params) override {
|
|
(void)params;
|
|
return golden<proto::DownloadAddResult>("download.add");
|
|
}
|
|
|
|
proto::HandlerResult<proto::DownloadAddBatchResult> on_download_addBatch(const proto::DownloadAddBatchParams& params) override {
|
|
(void)params;
|
|
return golden<proto::DownloadAddBatchResult>("download.addBatch");
|
|
}
|
|
|
|
proto::HandlerResult<proto::BulkTaskResult> on_download_cancel(const proto::DownloadCancelParams& params) override {
|
|
(void)params;
|
|
return golden<proto::BulkTaskResult>("download.cancel");
|
|
}
|
|
|
|
proto::HandlerResult<proto::TaskDetail> on_download_get(const proto::DownloadGetParams& params) override {
|
|
(void)params;
|
|
return golden<proto::TaskDetail>("download.get");
|
|
}
|
|
|
|
proto::HandlerResult<proto::DownloadListResult> on_download_list(const proto::DownloadListParams& params) override {
|
|
(void)params;
|
|
return golden<proto::DownloadListResult>("download.list");
|
|
}
|
|
|
|
proto::HandlerResult<proto::BulkTaskResult> on_download_pause(const proto::DownloadPauseParams& params) override {
|
|
(void)params;
|
|
return golden<proto::BulkTaskResult>("download.pause");
|
|
}
|
|
|
|
proto::HandlerResult<proto::DownloadProbeResult> on_download_probe(const proto::DownloadProbeParams& params) override {
|
|
(void)params;
|
|
return golden<proto::DownloadProbeResult>("download.probe");
|
|
}
|
|
|
|
proto::HandlerResult<proto::DownloadProvideAuthResult> on_download_provideAuth(const proto::DownloadProvideAuthParams& params) override {
|
|
(void)params;
|
|
return golden<proto::DownloadProvideAuthResult>("download.provideAuth");
|
|
}
|
|
|
|
proto::HandlerResult<proto::DownloadRefreshUrlResult> on_download_refreshUrl(const proto::DownloadRefreshUrlParams& params) override {
|
|
(void)params;
|
|
return golden<proto::DownloadRefreshUrlResult>("download.refreshUrl");
|
|
}
|
|
|
|
proto::HandlerResult<proto::DownloadRemoveResult> on_download_remove(const proto::DownloadRemoveParams& params) override {
|
|
(void)params;
|
|
return golden<proto::DownloadRemoveResult>("download.remove");
|
|
}
|
|
|
|
proto::HandlerResult<proto::BulkTaskResult> on_download_resume(const proto::DownloadResumeParams& params) override {
|
|
(void)params;
|
|
return golden<proto::BulkTaskResult>("download.resume");
|
|
}
|
|
|
|
proto::HandlerResult<proto::BulkTaskResult> on_download_start(const proto::DownloadStartParams& params) override {
|
|
(void)params;
|
|
return golden<proto::BulkTaskResult>("download.start");
|
|
}
|
|
|
|
proto::HandlerResult<proto::TaskSummary> on_download_update(const proto::DownloadUpdateParams& params) override {
|
|
(void)params;
|
|
return golden<proto::TaskSummary>("download.update");
|
|
}
|
|
|
|
proto::HandlerResult<proto::GrabberHarvestResult> on_grabber_harvest(const proto::GrabberHarvestParams& params) override {
|
|
(void)params;
|
|
return golden<proto::GrabberHarvestResult>("grabber.harvest");
|
|
}
|
|
|
|
proto::HandlerResult<proto::GrabberStartResult> on_grabber_start(const proto::GrabberStartParams& params) override {
|
|
(void)params;
|
|
return golden<proto::GrabberStartResult>("grabber.start");
|
|
}
|
|
|
|
proto::HandlerResult<proto::GrabberStatusResult> on_grabber_status(const proto::GrabberStatusParams& params) override {
|
|
(void)params;
|
|
return golden<proto::GrabberStatusResult>("grabber.status");
|
|
}
|
|
|
|
proto::HandlerResult<proto::Limiter> on_limiter_get(const proto::LimiterGetParams& params) override {
|
|
(void)params;
|
|
return golden<proto::Limiter>("limiter.get");
|
|
}
|
|
|
|
proto::HandlerResult<proto::Limiter> on_limiter_set(const proto::Limiter& params) override {
|
|
(void)params;
|
|
return golden<proto::Limiter>("limiter.set");
|
|
}
|
|
|
|
proto::HandlerResult<proto::MediaAddVariantResult> on_media_addVariant(const proto::MediaAddVariantParams& params) override {
|
|
(void)params;
|
|
return golden<proto::MediaAddVariantResult>("media.addVariant");
|
|
}
|
|
|
|
proto::HandlerResult<proto::MediaListVariantsResult> on_media_listVariants(const proto::MediaListVariantsParams& params) override {
|
|
(void)params;
|
|
return golden<proto::MediaListVariantsResult>("media.listVariants");
|
|
}
|
|
|
|
proto::HandlerResult<proto::QueueListResult> on_queue_list(const proto::QueueListParams& params) override {
|
|
(void)params;
|
|
return golden<proto::QueueListResult>("queue.list");
|
|
}
|
|
|
|
proto::HandlerResult<proto::QueueReorderResult> on_queue_reorder(const proto::QueueReorderParams& params) override {
|
|
(void)params;
|
|
return golden<proto::QueueReorderResult>("queue.reorder");
|
|
}
|
|
|
|
proto::HandlerResult<proto::QueueStartResult> on_queue_start(const proto::QueueStartParams& params) override {
|
|
(void)params;
|
|
return golden<proto::QueueStartResult>("queue.start");
|
|
}
|
|
|
|
proto::HandlerResult<proto::QueueStopResult> on_queue_stop(const proto::QueueStopParams& params) override {
|
|
(void)params;
|
|
return golden<proto::QueueStopResult>("queue.stop");
|
|
}
|
|
|
|
proto::HandlerResult<proto::QueueUpsertResult> on_queue_upsert(const proto::QueueUpsertParams& params) override {
|
|
(void)params;
|
|
return golden<proto::QueueUpsertResult>("queue.upsert");
|
|
}
|
|
|
|
proto::HandlerResult<proto::RulesListResult> on_rules_list(const proto::RulesListParams& params) override {
|
|
(void)params;
|
|
return golden<proto::RulesListResult>("rules.list");
|
|
}
|
|
|
|
proto::HandlerResult<proto::RulesUpsertResult> on_rules_upsert(const proto::RulesUpsertParams& params) override {
|
|
(void)params;
|
|
return golden<proto::RulesUpsertResult>("rules.upsert");
|
|
}
|
|
|
|
proto::HandlerResult<proto::ScheduleGetResult> on_schedule_get(const proto::ScheduleGetParams& params) override {
|
|
(void)params;
|
|
return golden<proto::ScheduleGetResult>("schedule.get");
|
|
}
|
|
|
|
proto::HandlerResult<proto::ScheduleSetResult> on_schedule_set(const proto::ScheduleSetParams& params) override {
|
|
(void)params;
|
|
return golden<proto::ScheduleSetResult>("schedule.set");
|
|
}
|
|
|
|
proto::HandlerResult<proto::SessionHelloResult> on_session_hello(const proto::SessionHelloParams& params) override {
|
|
(void)params;
|
|
return golden<proto::SessionHelloResult>("session.hello");
|
|
}
|
|
|
|
proto::HandlerResult<proto::SessionPairResult> on_session_pair(const proto::SessionPairParams& params) override {
|
|
(void)params;
|
|
return golden<proto::SessionPairResult>("session.pair");
|
|
}
|
|
|
|
proto::HandlerResult<proto::SessionSubscribeResult> on_session_subscribe(const proto::SessionSubscribeParams& params) override {
|
|
(void)params;
|
|
return golden<proto::SessionSubscribeResult>("session.subscribe");
|
|
}
|
|
|
|
proto::HandlerResult<proto::SettingsGetResult> on_settings_get(const proto::SettingsGetParams& params) override {
|
|
(void)params;
|
|
return golden<proto::SettingsGetResult>("settings.get");
|
|
}
|
|
|
|
proto::HandlerResult<proto::SettingsSetResult> on_settings_set(const proto::SettingsSetParams& params) override {
|
|
(void)params;
|
|
return golden<proto::SettingsSetResult>("settings.set");
|
|
}
|
|
|
|
private:
|
|
// Every fixture-backed handler only ever succeeds. A missing or unparseable
|
|
// fixture is a bug in the suite, not a contract outcome, so it surfaces as
|
|
// InternalError rather than being dressed up as a real error code.
|
|
template <class T>
|
|
proto::HandlerResult<T> golden(const std::string& method) {
|
|
const nlohmann::json* value = results_(method);
|
|
if (value == nullptr)
|
|
return std::unexpected(proto::HandlerError{
|
|
proto::ErrorCode::InternalError, "no fixture for method " + method});
|
|
auto parsed = proto::parse<T>(*value, method);
|
|
if (!parsed)
|
|
return std::unexpected(proto::HandlerError{
|
|
proto::ErrorCode::InternalError,
|
|
"fixture for " + method + " failed to parse: " + parsed.error().message});
|
|
return std::move(*parsed);
|
|
}
|
|
|
|
std::function<const nlohmann::json*(const std::string&)> results_;
|
|
};
|
|
|
|
} // namespace velox::conformance
|