Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: return response interface for success/error #1725

Closed
wants to merge 3 commits into from

Conversation

danisharora099
Copy link
Collaborator

@danisharora099 danisharora099 commented Nov 22, 2023

For the parent issue: #1694, we want to structure all protocols to return error codes & enums over throwing exceptions.

This PR:

  • refactors Filter to return IFilterResponse which includes statusCode, message, requestId

Notes:

@danisharora099 danisharora099 changed the title feat!(filter): return response interface for success/error feat!: return response interface for success/error Nov 22, 2023
Copy link

github-actions bot commented Nov 22, 2023

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
Waku core 78.09 KB (+0.19% 🔺) 1.6 s (+0.19% 🔺) 251 ms (+55.73% 🔺) 1.9 s
Waku Simple Light Node 240.61 KB (+0.07% 🔺) 4.9 s (+0.07% 🔺) 433 ms (-14.88% 🔽) 5.3 s
ECIES encryption 73.02 KB (+0.21% 🔺) 1.5 s (+0.21% 🔺) 252 ms (-19.84% 🔽) 1.8 s
Symmetric encryption 73.03 KB (+0.21% 🔺) 1.5 s (+0.21% 🔺) 310 ms (+55.91% 🔺) 1.8 s
DNS discovery 120.85 KB (0%) 2.5 s (0%) 399 ms (+23.77% 🔺) 2.9 s
Privacy preserving protocols 125.78 KB (+0.13% 🔺) 2.6 s (+0.13% 🔺) 405 ms (+25.95% 🔺) 3 s
Light protocols 75.88 KB (+0.24% 🔺) 1.6 s (+0.24% 🔺) 199 ms (+30.25% 🔺) 1.8 s
History retrieval protocols 74.75 KB (+0.18% 🔺) 1.5 s (+0.18% 🔺) 183 ms (-37.76% 🔽) 1.7 s
Deterministic Message Hashing 5.65 KB (0%) 113 ms (0%) 75 ms (+45.39% 🔺) 188 ms

@danisharora099 danisharora099 force-pushed the feat/filter-response-interface branch from 55763e7 to 5ca284a Compare November 22, 2023 10:30
@danisharora099 danisharora099 marked this pull request as ready for review November 22, 2023 10:36
@danisharora099 danisharora099 requested a review from a team as a code owner November 22, 2023 10:36
return {
requestId: requestId,
statusCode: statusCode
};
} catch (e) {
throw new Error(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are still a few errors being thrown here and line 109. They should also be converted. Ideally nothing is throw and users entirely rely on the enum error

@@ -72,7 +73,7 @@ class Subscription {
async subscribe<T extends IDecodedMessage>(
decoders: IDecoder<T> | IDecoder<T>[],
callback: Callback<T>
): Promise<void> {
): Promise<IFilterResponse> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function can fail in several manners:

  1. locally (can't encode, other checks fail)
  2. on the communication (can't open stream, remote node does not reply)
  3. Remote node send an error back

All these cases should be covered with an Enum

Only in the case of (3) then you may want to return a "sub error", ie, what the remote peer returned.

Currently, this is still throwing exception on (1) and (2). It should not.

Finally, there is an opportunity to have common errors with light push. SendError should be re-used here and made more generic.

Do not we will change light push to also return error like filter, so while it's not there yet, knowing that should allow a common design. E.g. today light push remote peer failure does not include sub error, tomorrow it will.

);

if (!res || !res.length) {
throw Error(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove all throwing.

@danisharora099
Copy link
Collaborator Author

will be contd after #1682 as it involves a significant refactor (+ dispatch errors)

@danisharora099 danisharora099 marked this pull request as draft November 24, 2023 21:14
@fryorcraken
Copy link
Collaborator

@danisharora099 Please ping me or reset my review when ready to re-review.

@danisharora099
Copy link
Collaborator Author

superseded by #1694

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.

2 participants