Unverified Commit 98c23fc1 authored by Alexandru Vasile's avatar Alexandru Vasile Committed by GitHub
Browse files

Return error from subscription callbacks (#799)



* subscription: Allow errors in subscription callbacks
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* subscription: Remove the need to own the error
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* error: Build `ErrorObject` from `CallError` for improved ergonomics
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Update examples for the new subscription API
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Add alias for subscription result
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* macros: Render server subscription method with `ResultSubscription`
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Port `proc_macro` example to new API
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Rename `ResultSubscription` to `ReturnTypeSubscription` to avoid confusion
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Port all tests to new subscription API
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Update documentation
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Port benches
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Replace tabs with spaces & add documentation
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Add dummy error for subscriptions
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Implement `From` for `SubscriptionError`
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Return `SubscriptionError` when parsing params
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Rename `SubscriptionError` to `SubscriptionEmptyError`
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Change `accept` signature
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Port tests to new `accept` api
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Implement `pipe_from_try_stream` and `pipe_from_stream` for `PendingSubscription`
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Modify examples to ilustrate new API
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Fix docs tests
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Rename previously `SubscriptionResult` -> `InnerSubscriptionResult`
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Rename `ReturnTypeSubscription` -> `SubscriptionResult`
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Remove documentation line
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Implement `PipeFromStreamResult`
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Add comment for empty error
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Update proc-macros/src/lib.rs
Co-authored-by: Niklas Adolfsson's avatarNiklas Adolfsson <niklasadolfsson1@gmail.com>

* Update proc-macros/src/lib.rs
Co-authored-by: Niklas Adolfsson's avatarNiklas Adolfsson <niklasadolfsson1@gmail.com>

* Update proc-macros/src/lib.rs
Co-authored-by: Niklas Adolfsson's avatarNiklas Adolfsson <niklasadolfsson1@gmail.com>

* Change `ReturnTypeSubscription` -> `SubscriptionResult`
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Add `ResultConsumed` for `PipeFromStreamResult`
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Update examples to use `PipeFromStreamResult`
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Replace ConsumedResult with Options
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Log warning when subscription callback fails
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Change ubuntu test names
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* server: Make `pipe` methods of `SubscriptionSink` private
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* server: Remove `pipe_from_stream` method of `SubscriptionSink`
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* server: Update PipeFromStreamResult documentation
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Adjust tests to `SubscriptionSink::pipe_from_stream` private interface
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Add `accept-reject` API on `SubscriptionSink`
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Make `pipe_from_try_stream` public
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Maybe accept the subscription
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Revert "server: Remove `pipe_from_stream` method of `SubscriptionSink`"

This reverts commit d3c3ce9c

.

* Make `unsubscribe` channel optional on accepting the connection
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Pass `SubscriptionSink` to subscription callbacks
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Implement subscription sink state
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Submit `InvalidParams` if sink was never accepted
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Handle rejected sinks
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Remove `PendingSubscription`
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Fix doc tests
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* macro: Make subscription sink mutable
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Fix tests and examples
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* macro: Return `sink.reject()` result
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* tests: Add test for `SubscriptionSinkState`
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Test internal subscription sink state
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Fix `send_error` to not always return `false`
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Fix benches
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Remove `PipeFromStreamResult`
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Use valid Json-RPC return code for test errors
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Remove `SubscriptionSinkState`"

* Remodel state machine using `Option`s for `SubscriptionSink`s
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* tests: Double accept / reject API for `SubscriptionSink`
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Implement `SubscriptionAcceptRejectError` for error propagation
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Remove `maybe_accept` wrapper
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Update comments and documentation
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Update core/src/server/rpc_module.rs
Co-authored-by: Niklas Adolfsson's avatarNiklas Adolfsson <niklasadolfsson1@gmail.com>

* Update core/src/server/rpc_module.rs
Co-authored-by: Niklas Adolfsson's avatarNiklas Adolfsson <niklasadolfsson1@gmail.com>

* rpc_server: Add type alias for unsubscription calls
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* rpc_server: Improve comment regarding dropped error
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* style: Single line return errors
Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>

* Make comment more verbose
Co-authored-by: Niklas Adolfsson's avatarNiklas Adolfsson <niklasadolfsson1@gmail.com>
Co-authored-by: James Wilson's avatarJames Wilson <james@jsdw.me>
parent a35f8c30
Pipeline #200820 passed with stages
in 5 minutes and 42 seconds