Skip to content

Commit

Permalink
Merge pull request #2922 from cloudflare/maizatskyi/2024-10-14-custom…
Browse files Browse the repository at this point in the history
…-event-not-supported

CustomEvent::notSupported method to raise appropriate error (if any)
  • Loading branch information
mikea authored Oct 24, 2024
2 parents 08d3a63 + 264ec1b commit efb5ff9
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/workerd/api/hibernatable-web-socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ class HibernatableWebSocketCustomEventImpl final: public WorkerInterface::Custom
return typeId;
}

kj::Promise<Result> notSupported() override {
KJ_UNIMPLEMENTED("hibernatable web socket event not supported");
}

private:
// Returns `params`, but if we have a HibernationReader we convert it to a
// HibernatableSocketParams first.
Expand Down
4 changes: 4 additions & 0 deletions src/workerd/api/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ class QueueCustomEventImpl final: public WorkerInterface::CustomEvent, public kj
kj::Array<QueueRetryMessage> getRetryMessages() const;
kj::Array<kj::String> getExplicitAcks() const;

kj::Promise<Result> notSupported() override {
KJ_UNIMPLEMENTED("queue event not supported");
}

private:
kj::OneOf<rpc::EventDispatcher::QueueParams::Reader, QueueEvent::Params> params;
QueueEventResult result;
Expand Down
4 changes: 4 additions & 0 deletions src/workerd/api/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,10 @@ class TraceCustomEventImpl final: public WorkerInterface::CustomEvent {
return typeId;
}

kj::Promise<Result> notSupported() override {
KJ_UNIMPLEMENTED("trace event not supported");
}

private:
uint16_t typeId;
kj::Array<kj::Own<workerd::Trace>> traces;
Expand Down
4 changes: 4 additions & 0 deletions src/workerd/api/worker-rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,10 @@ class JsRpcSessionCustomEventImpl final: public WorkerInterface::CustomEvent {
return result;
}

kj::Promise<Result> notSupported() override {
JSG_FAIL_REQUIRE(TypeError, "The receiver is not an RPC object");
}

// Event ID for jsRpcSession.
//
// Similar to WebSocket hibernation, we define this event ID in the internal codebase, but since
Expand Down
3 changes: 3 additions & 0 deletions src/workerd/io/worker-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ class WorkerInterface: public kj::HttpService {
capnp::ByteStreamFactory& byteStreamFactory,
rpc::EventDispatcher::Client dispatcher) = 0;

// The event is not supported by the target, raise an appropriate error.
virtual kj::Promise<Result> notSupported() = 0;

// Get the type for this event for logging / metrics purposes. This is intended for use by the
// RequestObserver. The RequestObserver implementation will define what numbers correspond to
// what types.
Expand Down
6 changes: 3 additions & 3 deletions src/workerd/server/server.c++
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ private:
throwUnsupported();
}
kj::Promise<CustomEvent::Result> customEvent(kj::Own<CustomEvent> event) override {
throwUnsupported();
return event->notSupported();
}

[[noreturn]] void throwUnsupported() {
Expand Down Expand Up @@ -875,7 +875,7 @@ private:
throwUnsupported();
}
kj::Promise<CustomEvent::Result> customEvent(kj::Own<CustomEvent> event) override {
throwUnsupported();
return event->notSupported();
}

[[noreturn]] void throwUnsupported() {
Expand Down Expand Up @@ -1153,7 +1153,7 @@ private:
throwUnsupported();
}
kj::Promise<CustomEvent::Result> customEvent(kj::Own<CustomEvent> event) override {
throwUnsupported();
return event->notSupported();
}

[[noreturn]] void throwUnsupported() {
Expand Down

0 comments on commit efb5ff9

Please sign in to comment.